for(int i=0;i<20;i++)
{
string cName="textbox"+i;
TextBox tb= this.Controls.Find(cName) as TextBox
tb.Text=....
}
{
string cName="textbox"+i;
TextBox tb= this.Controls.Find(cName) as TextBox
tb.Text=....
}
解决方案 »
- gdal/ogr 类库问题(“OSGeo.OGR.Ogr”的类型初始值设定项引发异常)
- 正则表达式读取匹配项
- 想做一个功能,用VSTO,在自己的程序中把xml文件路径传给excel2007,然后自动打开excel,可以进行编辑,然后还可以保存,求思路..
- 关于c#多线程的一个问题,在线等!
- DataGridView与图片显示问题
- System.Type.GetType的问题
- C# 如何通过postdata的方法,自动提交,回答百度知道的问题
- 关于combobox的一个问题
- 新手求高手教..C#在winform中如何实现在datagridl里显示ACCESS数据库的内容.请给我完整的代码好吗?我是新手呀....
- 怎样在datagrid中隐藏行?
- C#获取电子秤重量
- 怎样将datagrideview里面的容存放到xml文件中并且自定义xml文件名称保存
foreach(var v in this.Controls)
{
TextBox tb= v as TextBox;
if(vb!=null)
{
tb.Enabled=false;
}
}
for(int i=0;i<this.Controls.Count;i++)
{
Control c = this.Controls[i];
if(c is TextBox)
{
TextBox tb= c as TextBox;
//......
}
}
txt[0]=new System.Windows.Forms.TextBox();
txt[1]=new System.Windows.Forms.TextBox();
txt[2]=new System.Windows.Forms.TextBox();
txt[3]=new System.Windows.Forms.TextBox();
txt[4]=new System.Windows.Forms.TextBox();
txt[5]=new System.Windows.Forms.TextBox();
txt[6]=new System.Windows.Forms.TextBox();
txt[7]=new System.Windows.Forms.TextBox();
/// <summary>
/// txt[0]
/// <summary>
this.txt[0].Location = new System.Drawing.Point(22, 299);
this.txt[0].Name = "txt[0]";
this.txt[0].Size = new System.Drawing.Size(108, 21);
this.txt[0].TabIndex = 20;
this.txt[0].Text = "0";
this.Controls.Add(this.txt[0]);
/// <summary>
/// txt[1]
/// <summary>
this.txt[1].Location = new System.Drawing.Point(112, 299);
this.txt[1].Name = "txt[1]";
this.txt[1].Size = new System.Drawing.Size(108, 21);
this.txt[1].TabIndex = 21;
this.txt[1].Text = "1";
this.Controls.Add(this.txt[1]);
/// <summary>
/// txt[2]
/// <summary>
this.txt[2].Location = new System.Drawing.Point(202, 299);
this.txt[2].Name = "txt[2]";
this.txt[2].Size = new System.Drawing.Size(108, 21);
this.txt[2].TabIndex = 22;
this.txt[2].Text = "2";
this.Controls.Add(this.txt[2]);
/// <summary>
/// txt[3]
/// <summary>
this.txt[3].Location = new System.Drawing.Point(292, 299);
this.txt[3].Name = "txt[3]";
this.txt[3].Size = new System.Drawing.Size(108, 21);
this.txt[3].TabIndex = 23;
this.txt[3].Text = "3";
this.Controls.Add(this.txt[3]);
/// <summary>
/// txt[4]
/// <summary>
this.txt[4].Location = new System.Drawing.Point(382, 299);
this.txt[4].Name = "txt[4]";
this.txt[4].Size = new System.Drawing.Size(108, 21);
this.txt[4].TabIndex = 24;
this.txt[4].Text = "4";
this.Controls.Add(this.txt[4]);
/// <summary>
/// txt[5]
/// <summary>
this.txt[5].Location = new System.Drawing.Point(472, 299);
this.txt[5].Name = "txt[5]";
this.txt[5].Size = new System.Drawing.Size(108, 21);
this.txt[5].TabIndex = 25;
this.txt[5].Text = "5";
this.Controls.Add(this.txt[5]);
/// <summary>
/// txt[6]
/// <summary>
this.txt[6].Location = new System.Drawing.Point(562, 299);
this.txt[6].Name = "txt[6]";
this.txt[6].Size = new System.Drawing.Size(108, 21);
this.txt[6].TabIndex = 26;
this.txt[6].Text = "6";
this.Controls.Add(this.txt[6]);
/// <summary>
/// txt[7]
/// <summary>
this.txt[7].Location = new System.Drawing.Point(652, 299);
this.txt[7].Name = "txt[7]";
this.txt[7].Size = new System.Drawing.Size(108, 21);
this.txt[7].TabIndex = 27;
this.txt[7].Text = "7";
this.Controls.Add(this.txt[7]);
private System.Windows.Forms.TextBox[] txt;
this.Controls.Cast<Control>().Where(x => x is TextBox).ToList().ForEach(new Action<Control>(x => x.Enabled = false));//对前20个TextBox操作
Enumerable.Range(0, 20).Select(x => this.Controls.Cast<Control>().Where(y => y is TextBox).ToList()[x]).ToList().ForEach(new Action<Control>(k => k.Enabled = false));
string cName="textbox"+i;
只会找txtbox0 .....txtbox19 这20个啊
你这个是对所有的textbox进行处理,我只想操作一部分,比较前面20个
string cName="textbox"+i;
只会找txtbox0 .....txtbox19 这20个啊
20修改下不就可以了么 ?还是LZ纠结是什么问题?