VB.NET 迭代控制容器
如何循环访问容器内的所有控件以及包含控件的容器中的所有控件,等等。
Form
-Panel
--Control
--Tab
----Control
----Control
--Tab
----Control
以下仅检索 -Panel,而不检索任何其他控件
For Each cntrl As Control In Me.Controls
Next
如何在 For Each 循环中检索所有控件,而无需为堆栈中的每个级别使用 If/Then?
编辑:
Dim ctl As Control = Me
Do
ctl = Me.GetNextControl(ctl, True)
'Do whatever you have to ctl
Loop Until ctl Is Nothing
这是迄今为止我发现的最好的方法。
How do I go about looping through all the controls within a container, and all the controls in the container of a containing control, and so on.
Form
-Panel
--Control
--Tab
----Control
----Control
--Tab
----Control
The following only retrieves -Panel and none of the other controls
For Each cntrl As Control In Me.Controls
Next
How can I retrieve them all in a For Each loop without an If/Then for every level in the stack?
EDIT:
Dim ctl As Control = Me
Do
ctl = Me.GetNextControl(ctl, True)
'Do whatever you have to ctl
Loop Until ctl Is Nothing
This is so far the best method I found of doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须定义一个方法来
递归
遍历容器内的容器。像这样的:调用这个方法:
You have to define a method that
recursively
traverse containers inside the container. Something like this:To call this method: