如何遍历Button按钮 在一个窗体中有多个(数目不定)Button,name分别为:Button1、Button2、Button3.....如何用for循环遍历buttonfor(int i=1;i<n;i++){Button(i=1为Button1,i=2为Button2).visible=true;} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void FindTop(){foreach (Control c in this.Controls){ if (c.GetType() == typeof(Button)) c.Visible = true; if (c.Controls.Count > 0) FindChild(c); }}void FindChild(Control Parent){foreach (Control c in Parent){ if (c.GetType() == typeof(Button)) c.Visible = true; if (c.Controls.Count > 0) FindChild(c); }} foreach(Control c in this.Controls){ if(c is Button){}}或Control[] controls = this.Controls; foreach(Control ctl in this.Controls){if(ctl is Button) ctl.Visible=true;} void FindChild(Control Parent){foreach (Control c in Parent){ if (c.GetType() == typeof(Button)) c.Visible = true; if (c.Controls.Count > 0) FindChild(c); }}修正下:void FindChild(Control Parent){foreach (Control c in Parent.Controls){ if (c.GetType() == typeof(Button)) c.Visible = true; if (c.Controls.Count > 0) FindChild(c); }} foreach (Control tmpControl in this.Controls) { if (tmpControl is Button) { tmpControl.Visible = false; } } 获取 Control.Name 属性,然后得到 n。 this.Controls[string.Format("button{0}", i)].Visible = true; for (int i = 0; i < n; i++)if (this.Controls[string.Format("button{0}", i)] != null) this.Controls[string.Format("button{0}", i)].Visible = true; "name分别为:Button1、Button2、Button3"asp.net遍历,直接this.Controlsjs遍历,直接document.all 想到怎么做了,谢谢大家 foreach (Control c in this.Controls) { if (c.GetType() == typeof(Button)) { for (int i = 1; i < n; i++) { if(c.Name=="button"+i) c.visible = true; } } } C#斐波那契数列~ 线程间操作无效: 从不是创建控件“clientList”的线程访问它 急救!!! 求动态数组实例 初级数据库建立及存储及使用及学习及问题 winform中的dll文件问题!!! 有没有可以在.net中和flash actionscript中通用的加/解密算法 WeifenLuo组件 请问有哪位大侠会用C#视频编程,或则懂视频编程? 子窗口通过委托能访问MDI窗口的类,却无法更新父窗口控件的值。 C#关于日期控件的问题 文件浏览器不同文件显示不同图标
{
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(Button)) c.Visible = true;
if (c.Controls.Count > 0) FindChild(c);
}
}void FindChild(Control Parent)
{
foreach (Control c in Parent)
{
if (c.GetType() == typeof(Button)) c.Visible = true;
if (c.Controls.Count > 0) FindChild(c);
}
}
{
if(c is Button){}
}
或Control[] controls = this.Controls;
{
if(ctl is Button)
ctl.Visible=true;
}
{
foreach (Control c in Parent)
{
if (c.GetType() == typeof(Button)) c.Visible = true;
if (c.Controls.Count > 0) FindChild(c);
}
}
修正下:
void FindChild(Control Parent)
{
foreach (Control c in Parent.Controls)
{
if (c.GetType() == typeof(Button)) c.Visible = true;
if (c.Controls.Count > 0) FindChild(c);
}
}
{
if (tmpControl is Button)
{
tmpControl.Visible = false;
}
}
if (this.Controls[string.Format("button{0}", i)] != null) this.Controls[string.Format("button{0}", i)].Visible = true;
{
if (c.GetType() == typeof(Button))
{
for (int i = 1; i < n; i++)
{
if(c.Name=="button"+i)
c.visible = true; }
}
}