I have a TextBox that is added to each new tab control tab page that gets created at runtime. All properties are set properly (eg Multiline, etc), but when i try to access the textbox from coedbehind there is no option for it. How do I set wordwrap on or off when it's inside a tabcontol's tabpage?
The Controls
collection is typed as a collection of Control
objects. You will need to cast the returned control to TextBox
first:
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.