我知道如何遍历控件,但“components”属性似乎并不直接可用。我在运行时查看对象时可以看到它们,但我不知道如何访问它们。任何帮助将不胜感激。
答案 0 :(得分:0)
我发现我可以使用反射来获得我想要的东西,因为.components是私有的:
Dim formType As Type = myForm.GetType()
Dim fieldInfo As Reflection.FieldInfo = formType.GetField("components", BindingFlags.Instance Or BindingFlags.NonPublic)
If fieldInfo IsNot Nothing Then
Dim parent As IContainer = DirectCast(fieldInfo.GetValue(myForm), IContainer)
If parent IsNot Nothing Then
For Each comp As Component In parent.Components
Next
End If
End If