foreach(Control mycontrol in this.Controls) { if(mycontrol is TextBox) (TextBox)mycontrol.Text=""; if(mycontrol is ComboBox) (TextBox)mycontrol.Items.Clear(); }
我想楼主是为了简简单单地初始化一个窗口吧。 foreach(Control c in this.Controls) if(typeof(TextBox).IsInstantof(c) || typeof(ComboBox).IsInstantof(c)) c.Text=String.Empty; 刚好三句,不过没测试过,也不知道行不行,另外也不知道方法IsInstantof写得有没有错,这个倒可以自已查一查。
{
if(mycontrol is TextBox)
(TextBox)mycontrol.Text="";
if(mycontrol is ComboBox)
(TextBox)mycontrol.Items.Clear();
}
(ComboBox)mycontrol.Items.Clear();
将数据集clear()就OK了等于没说楼主不要打我哈~~~~
foreach(Control c in this.Controls)
if(typeof(TextBox).IsInstantof(c) || typeof(ComboBox).IsInstantof(c))
c.Text=String.Empty;
刚好三句,不过没测试过,也不知道行不行,另外也不知道方法IsInstantof写得有没有错,这个倒可以自已查一查。