具有相同事件的文本框数组(array of textboxes with the same event)

编程入门 行业动态 更新时间:2024-10-28 07:18:33
具有相同事件的文本框数组(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

本文发布于:2023-08-04 16:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417920.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   文本框   事件   event   textboxes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!