我尝试在sub中对我的许多控件执行某些操作。但是我有一些麻烦来访问我的自定义UserControl的属性。 这是通用代码的一部分:
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is CheckBox Then
CheckBoxes_CheckStateChanged(ctrl, e)
End If
If TypeOf ctrl Is MyUserControl Then
ctrl.MyProperty = true
End If
Next
这对CheckBox部分正常工作,但MyUserControl部分不可用:MyProperty未建议或无法访问。
如何以自动方式访问并影响自定义UserControl属性的值?
PS:我在紧凑框架上工作
答案 0 :(得分:2)
你需要转换ctrl,因为它的类型是控件
If TypeOf ctrl Is MyUserControl Then
CType(ctrl, MyUserControl).MyProperty = true
End If