I have 3 Controls
inside a TabPage tabpage1
; let's call them panel1
, panel2
and datagridview1
. I'm trying to make a general method for accessing panel2
. How do I access this Panel
in TabPage.Controls
? I've found out that I can use something like tabpage1.Controls[1]
. But how do I know the index of panel2
? And how do I set its index?
I believe you can use the controls collection.
var ctrls = this.Controls.Find("ControlName", true);
if (ctrls != null)
if(ctrls.Length != 0)
{
Control ctrl = ctrls[0];
}
I am not good in C# but I believe it works and you can easy make an universal method from it. ( this
only for the ilustrational purposes - replace with the apriopriate object.
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.