收集设计中创建的文本框
我通过拖放添加了几个文本框。现在我想将它们全部收集在一个文本框数组下。我知道如何在代码中创建文本框数组,但不知道如何收集设计期间创建的文本框。有人可以帮忙吗?
I added several textboxes by drag_n_dropping. Now I want to gather them all under a textbox array. I know how to create array of textboxes in code but not how to gather the textboxes created during design. Could anyone help please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有时,文本框不会直接放置在表单上,而是放置在容器控件(例如选项卡控件或拆分容器)上。如果您想找到所有这些文本框,递归会有所帮助
然后您通过将表单作为参数传递来调用
GetTextBoxes
这是可能的,因为
Form
本身派生自Control
。Sometimes the textboxes are not placed on the form directly but on a container control like a tab control or a split container. If you want to find all these textboxes, a recursion will help
Then you call
GetTextBoxes
by passing the form as argumentThis is possible, since
Form
itself derives fromControl
.这假设您的文本框位于同一个
GroupBox
或Panel
中。需要
使用 System.Linq;
。请注意,textBoxesWithinForm
将忽略groupBox
内的 TextBox,反之亦然。或者像 @Jeff 建议的那样,但不要通过 this.Controls 并比较 Control 是否是 Textbox:
This assumes your TextBoxes are within same
GroupBox
orPanel
.Requires
using System.Linq;
. Please note thattextBoxesWithinForm
will ignore TextBoxes that are withingroupBox
and vice versa.Or like
@Jeff
suggests but instead of going thru this.Controls and comparing if Control isTextbox
: