http://community.csdn.net/Expert/topic/4853/4853491.xml?temp=.2068903
解决了两天米有解决掉,现在求一个完整的解决方案
不想贴偶的代码了,解决了三天,还是重写一个
要求:用for 生成十个TextBox控件,命名规则为S1....S10
再取任意SX的值只有200分了,能解决者速帮忙啊
解决了两天米有解决掉,现在求一个完整的解决方案
不想贴偶的代码了,解决了三天,还是重写一个
要求:用for 生成十个TextBox控件,命名规则为S1....S10
再取任意SX的值只有200分了,能解决者速帮忙啊
{
TextBox txtTemp = new TextBox();
txtTemp.Name = "S" + i.ToString();
txtTemp.Parent = this;
txtTemp.Text = "S" + i.ToString();
txtTemp.Show();
}
{
myTextBoxs = new TextBox[comboBox1.SelectedIndex+1];
for (int i=1;i<=comboBox1.SelectedIndex+1;i++)
{
object a="S"+i.ToString ();
a = new Control(a.ToString ());
a= new TextBox ();
((TextBox)a).Name = a.ToString ();
((TextBox)a).Top=i*20;
((TextBox)a).Left =300;
this.Controls .Add ((Control)a);
myTextBoxs[i]=a;
} }private void button2_Click(object sender, System.EventArgs e)
{
for (int i=1;i<=comboBox1.SelectedIndex+1;i++)
{
string xxx = this.myTextBoxs[i].Text;
}
}
{
myTextBoxs = new TextBox[comboBox1.SelectedIndex+1];
for (int i=1;i<=comboBox1.SelectedIndex+1;i++)
{
object a="S"+i.ToString ();
a = new Control(a.ToString ());
a= new TextBox ();
((TextBox)a).Name = a.ToString ();
((TextBox)a).Top=i*20;
((TextBox)a).Left =300;
this.Controls .Add ((Control)a);
myTextBoxs[i]=a;
} }private void button2_Click(object sender, System.EventArgs e)
{
for (int i=1;i<=comboBox1.SelectedIndex+1;i++)
{
string xxx = this.myTextBoxs[i].Text;
}
}
再取任意SX的值无非就是名字与Array建立对应关系,只不过对于S1....S10来说,不是变量名,而是textbox的name属性而已,因此在获取某项值的时候,是需要遍历,然后通过name属性来判断。
myTextBoxs[i]=(TextBox)a;
不过还是谢谢大家了
TextBox txt = null;
for (int i = 0; i <= 9; i++)
{
txt = new TextBox();
txt.Name = "S" + i;
txt.Text = "value" + i;
txt.Location = new Point(10, 25*i);
this.Controls.Add(txt);
}
//提示,最好你把所有的控件添加到一个panel中,然后你可以通过panel中的Controls[i]取得控件
MessageBox.Show(Controls[2].Text);