间接调用无法访问用户控件 属性

User control property not reachable from indirect call

我尝试在 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:我在紧凑型框架上工作

您需要转换 ctrl,因为它的类型是 control

If TypeOf ctrl Is MyUserControl Then
    CType(ctrl, MyUserControl).MyProperty = true
End If