简体   繁体   English

无法在TabControl内的TextBox上设置WordWrap选项

[英]Cannot set WordWrap option on TextBox inside TabControl

I have a TextBox that is added to each new tab control tab page that gets created at runtime. 我有一个TextBox,添加到每个新的选项卡控件标签页,在运行时创建。 All properties are set properly (eg Multiline, etc), but when i try to access the textbox from coedbehind there is no option for it. 所有属性都设置正确(例如Multiline等),但是当我尝试从coedbehind访问文本框时,没有选项。 How do I set wordwrap on or off when it's inside a tabcontol's tabpage? 如何在tabcontol的标签页中设置wordwrap打开或关闭?

在此输入图像描述

The Controls collection is typed as a collection of Control objects. Controls集合被输入为Control对象的集合。 You will need to cast the returned control to TextBox first: 您需要首先将返回的控件TextBoxTextBox

TextBox textBox = tabControl1.SelectedTab.Controls[0] as TextBox;
if (textBox != null)
{
    textBox.WordWrap = true;
}

try below 试试下面

var txtBox= tabControl1.SelectedTab.Controls.OfType<TextBox>().FirstOrDefault() as TextBox;
if(txtBox != null)
{
   // do something like txtBox.WordWrap = true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM