4

在我们的 IDE(例如 Visual Studio)中,如果我们显示 System.Windows.Forms.Button 控件的属性,我们会看到一些属性公开了另一组属性。例如:平面外观、字体、位置、边距等。

我想在自定义控件中做类似的事情。

我知道后面的代码是错误的,但这是我正在尝试做的一个例子:

Public Class StateOfMyCustomControl

    Public Enum EnumVisibility
        Visible
        NonVisible
    End Enum

    Public Enum EnumEventManagement
        Automatic
        Manual
    End Enum

    Private mAssociatedControl As MyCustomControl
    Private mVisibility As EnumVisibility
    Private mEventManagement As EnumEventManagement

    Public Sub New(ByVal AssociatedControl As MyCustomControl)
        mAssociatedControl = AssociatedControl
    End Sub

    Public Property Visibility() As EnumVisibility
        Get
            Return mVisibility
        End Get
        Set(ByVal value As EnumVisibility)

            mVisibility = value

            mAssociatedControl.Visible = False
            If mVisibility = EnumVisibility.Visible Then
                mAssociatedControl.Visible = True
            End If

        End Set
    End Property

    Public Property EventManagement() As EnumEventManagement
        Get
            Return mEventManagement
        End Get
        Set(ByVal value As EnumEventManagement)
            mEventManagement = value
        End Set
    End Property

End Class

Public Class MyCustomControl

    ' ...

    Private mState As StateOfMyCustomControl

    Public Sub New()
        mState = New StateOfMyCustomControl(Me)
    End Sub

    Public Property State() As StateOfMyCustomControl
        Get
            Return mState
        End Get
        Set(ByVal value As StateOfMyCustomControl)
            mState = value
        End Set
    End Property

    ' ...

End Class

在我的 IDE 中,在我的自定义控件的属性窗口中,我想查看我的属性State,并可以显示它以设置属性VisibilityEventManagement

非常感谢

4

1 回答 1

3

您需要告诉它使用ExpandableObjectConverter(或自定义转换器)用于StateOfMyCustomControl. 在 C# 中,这是:

[TypeConverter(typeof(ExpandableObjectConverter))]
public class StateOfMyCustomControl {...}

但是,您在 VB 中应用属性,请执行此操作;-p

可能:

<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class StateOfMyCustomControl
...
于 2009-04-16T10:27:56.867 回答