控件遍历是分层次的,比如下面代码,只能遍历窗口的根级控件,比如有一个panel,panel里面有一个按钮,这种代码是遍历不到panel里面的按钮的。
For Each c As Winform.Control In e.Form.Controls
Output.Show(c.Gettype().fullname)
Next
如果要遍历到panel里面的按钮需要再下一层才行,比如
For Each c As Winform.Control In e.Form.Controls
If Typeof c Is WinForm.panel Then
Output.Show(c.Name)
Dim p As WinForm.panel = c
For Each c2 As Winform.Control In p.Children
Output.Show(c2.Name)
Next
End If
Next
所以不是判断当前控件是否在一个panel上,而是判断panel里有什么子控件