I have a panel, where my program is adding dynamic controls. Either I want to access these controls at runtime for changing their colors or texts.
the only way I know is:
Control [] myControls = myPanel.Controls.Find( name , true );
Here the problem is, my dynamic Controls have not any name ! Their name are " null ". If I'm trying name as a null value, it gives error. How can I achieve it ? Must I give every added control a name ?
Thanks.
You could loop through the Controls collection:
foreach(var control in myPanel.Controls) {
//Here you do something with the appropriate control.
}
Could just do something like this:
foreach(Control control in myPanel.Controls)
control.Backcolor=Color.Black;
也许您可以只保留对每个动态添加的控件的引用(例如,实例字段,在字典中等),并在以后需要访问控件时使用它。
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.