C# 在panel 上动态添加自定义控件textbox,为什么不能再添加的textbox 中输入字符呢?
inti=0;privatevoidbutton5_Click(objectsender,EventArgse){tb.Name="tb_"+i.Tostring();t...
int i=0;
private void button5_Click(object sender, EventArgs e)
{
tb.Name = "tb_"+i.Tostring();
tb.Text =(i+2).Tostring() ;
tb.Width = 200;
tb.Height = 30;
tb.Location = new Point(0,0+i*30);
i++;
this.panel1.Controls.Add(tb);
}
} 展开
private void button5_Click(object sender, EventArgs e)
{
tb.Name = "tb_"+i.Tostring();
tb.Text =(i+2).Tostring() ;
tb.Width = 200;
tb.Height = 30;
tb.Location = new Point(0,0+i*30);
i++;
this.panel1.Controls.Add(tb);
}
} 展开
1个回答
展开全部
我试了下面的代码是可以的:
int i = 0;
private void button1_Click(object sender, EventArgs e)
{
TextBox tb = new TextBox();
tb.Name = "tb_" + i.ToString();
tb.Text = (i + 2).ToString();
tb.Width = 200;
tb.Height = 30;
tb.Location = new Point(0, 0 + i * 30);
i++;
this.panel1.Controls.Add(tb);
}
追问
我知道是什么原因了! 谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询