具有相同事件的文本框数组(array of textboxes with the same event)
我正在与c#的窗体应用程序项目工作,我正在尝试使用相同的事件操作使TextBox数组。 我的意思是需要N个文本框(N与用户分配不同),而所有“TextBox_TextChanged”事件都是相同的。 如果你能帮助我,我会很感激。
I'm working on a windows form application project with c# and I’m trying to make an array of TextBox with the same event action. I mean N TextBoxes are required (N is different as user assign) while all the “TextBox_TextChanged “ event are same. I would appreciated it if you would help me.
最满意答案
请试试这个。
private void frmMain_Load(object sender, EventArgs e) { int userPermittedCount = 4 // You can add user defined permission no : of text box count here; int pointX = 30; int pointY = 40; for (int i = 0; i < userPermittedCount; i++) { TextBox txtBox = new TextBox(); txtBox.Location = new Point(pointX, pointY); this.Controls.Add(txtBox); this.Show(); pointY += 20; txtBox.TextChanged += txtAdd_TextChanged; } } private void txtAdd_TextChanged(object sender, EventArgs e) { }Please try this.
private void frmMain_Load(object sender, EventArgs e) { int userPermittedCount = 4 // You can add user defined permission no : of text box count here; int pointX = 30; int pointY = 40; for (int i = 0; i < userPermittedCount; i++) { TextBox txtBox = new TextBox(); txtBox.Location = new Point(pointX, pointY); this.Controls.Add(txtBox); this.Show(); pointY += 20; txtBox.TextChanged += txtAdd_TextChanged; } } private void txtAdd_TextChanged(object sender, EventArgs e) { }更多推荐
TextBox,相同,事件,电脑培训,计算机培训,IT培训"/> <meta name="description&quo
发布评论