has*_*shi 10
List<Control> list = new List<Control>();
GetAllControl(this, list);
foreach (Control control in list)
{
if (control.GetType() == typeof(Button))
{
//all btn
}
}
private void GetAllControl(Control c , List<Control> list)
{
foreach (Control control in c.Controls)
{
list.Add(control);
if (control.GetType() == typeof(Panel))
GetAllControl(control , list);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我所做的,我编写了一个简单的函数,当我单击一个Button时,我只选择Panel Control并将其传递给一个函数,以进一步循环通过该面板上的控件.
private void cmdfind_Click(object sender, EventArgs e)
{
try
{
foreach (Control control in this.Controls)
{
if (control.GetType() == typeof(Panel))
//AddToList((Panel)control); //this function pass the panel object so further processing can be done
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27757 次 |
| 最近记录: |