winform中如何获得窗体中所有的控件 我想用遍例查出窗体内所有的botton控件。如何写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach(Control ctl in Controls) { ... } foreach(Control c in this.Controls) { switch(c.GetType().Name.ToUpper()) { case "Button": default: } } foreach(Control ctl in Controls) { if(ctl is Button) //or if(ctl.GetType()==(new Button()).GetType) .. //其它类似 } BLL.dIsplayServerList(cboServers); foreach (Control ctr in this.Controls) { if (ctr is Button) { } } private List<Button> getButton() { foreach (Control c in this.Controls) { List<Button> list = new List<Button>(); if (c.GetType().ToString() == "System.Windows.Forms.Button") { list.Add(c); } } return List; } 考虑容器控件. 若button在容器里.private void seachbutton(Control.ControlCollection controls) { foreach (Control c in controls) { if (c is Button) { .....} else if (c.Controls.Count > 0) seachbutton(c.Controls); } }执行: seachbutton(this.Controls); foreach (Control ctr in this.Controls) { if (ctr.getGetType().ToString() == "System.Windows.Forms.Button") { this.textBox1.Focus(); } } 请问我这样写怎么不能让textBox1获得焦点呢? 跟踪一下, 看 this.textBox1.Focus(); 有没有执行.若你的button是在一个容器里, 则this.textBox1.Focus(); 就不会执行. 我的button不在容器里。。但是跟踪了没执行这句话啊 socket 传送xml 关于字符串的操作问题,请教高手 一个简单的Dataview问题 关于DataGridView里面放置ComboBox列的问题 C# 打开子窗体怎么关闭主窗体 c# webservice 中如何得到客户端的 ip地址? C#的Toolbar的Button问题 请教一个转换问题 c# 类库中有没有关于FtpClient的类 托管非托管的概念如何清楚划分的,有何意义。 Linq问题 代码设置windows 2003中的文件属性
foreach(Control ctl in Controls)
{
...
}
foreach(Control c in this.Controls)
{
switch(c.GetType().Name.ToUpper())
{
case "Button":
default:
}
}
foreach(Control ctl in Controls)
{
if(ctl is Button) //or if(ctl.GetType()==(new Button()).GetType)
..
//其它类似
}
foreach (Control ctr in this.Controls)
{
if (ctr is Button)
{ }
}
{
foreach (Control c in this.Controls)
{
List<Button> list = new List<Button>();
if (c.GetType().ToString() == "System.Windows.Forms.Button")
{
list.Add(c);
}
}
return List;
}
{
foreach (Control c in controls)
{
if (c is Button)
{ .....}
else
if (c.Controls.Count > 0)
seachbutton(c.Controls);
} }执行:
seachbutton(this.Controls);
{
if (ctr.getGetType().ToString() == "System.Windows.Forms.Button")
{
this.textBox1.Focus();
}
} 请问我这样写怎么不能让textBox1获得焦点呢?