我有以下代码在每个按钮单击上创建一个文本框:
private void AddNewTimer_Click(object sender, EventArgs e)
{
int timerCount = 0;
int boxY = 0;
if (timerCount <= 6)
{
timerCount++;
TextBox txt = new TextBox();
txt.ID = "timer" + timerCount++;
txt.Text = Convert.ToString(timerCount);
txt.Name = Convert.ToString(timerCount);
txt.Width = 63;
txt.Location = new Point(0, boxY);
TimerContainer.Controls.Add(txt);
boxY = boxY + 25;
}
}
Run Code Online (Sandbox Code Playgroud)
txt.ID = timerCount++;给我'TextBox' does not contain a definition for 'ID',虽然在回答说明这个问题,在这个页面.
您正在混合ASP.Net和Windows窗体.在ASP.Net中你有ID.在Windows窗体中,您可以通过Name属性访问控件.
更新:
您的代码实际上是创建多个文本框但位置相同.每次Y坐标都会重置.您可能想要成为boxY私人会员.
| 归档时间: |
|
| 查看次数: |
133 次 |
| 最近记录: |