Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 在自定义控件中对属性进行分组_.net_Vb.net_Custom Controls - Fatal编程技术网

.net 在自定义控件中对属性进行分组

.net 在自定义控件中对属性进行分组,.net,vb.net,custom-controls,.net,Vb.net,Custom Controls,在我们的IDE中,例如Visual Studio,如果我们显示System.Windows.Forms.Button控件的属性,我们会看到一些属性公开另一组属性。例如:平面外观、字体、位置、边距等 我想在自定义控件中执行类似的操作 我知道隐藏的代码是错误的,但下面是一个我正在尝试做的示例: Public Class StateOfMyCustomControl Public Enum EnumVisibility Visible NonVisible

在我们的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中,在自定义控件的properties窗口中,我希望看到我的属性状态,并可以显示它来设置属性可见性和EventManagement


非常感谢

您需要告诉它使用
ExpandableObjectConverter
(或自定义转换器)进行MyCustomControl的
状态
。在C#中,这是:

[TypeConverter(typeof(ExpandableObjectConverter))]
public class StateOfMyCustomControl {...}
不管你如何在VB中应用属性,都要这样做-p

可能:

<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class StateOfMyCustomControl
...
_
MyCustomControl的公共类状态
...

Hi Marc,我已导入System.ComponentModel命名空间以使用TypeConverter属性。我已经证明了这一点,效果很好。非常感谢!