我想可以用下面的方法试试:
for(int i=0;i<this.Controls.Count;i++)
{
object obj=this.Controls[i];
if(obj is Button) MessageBox.Show("Button");
}
for(int i=0;i<this.Controls.Count;i++)
{
object obj=this.Controls[i];
if(obj is Button) MessageBox.Show("Button");
}
大哥这不是遍历是什么?哈哈哈
{
Hashtable ht = new Hashtable();
Button bt;
public YourForm()
{
bt = new Button();
bt.Text = "Whatever";
Controls.Add(bt);
ht["Whatver"] = bt;
}...
}to get the control, use ht["Whatver"];
FindControl("id")是web方式下查找控件的方法http://www.csdn.net/expert/topic/1083/1083153.xml?temp=.9578668
适合于使用类的情况
我得控件有很多控件不是程序生成的,看来saucer(思归)的方法也不行
--效率(编程时)比用遍历差多了吧
在恰当的时候遍历,在遍历的时候构建Hash表,之后就通过访问Hash获得