4
在我們的IDE中,例如Visual Studio,如果我們顯示System.Windows.Forms.Button控件的屬性,則會看到一些暴露一組屬性的屬性。例如:FlatAppearance,Font,Location,Margin,等等。自定義控件中的組屬性
我想在自定義控件中做類似的事情。
我知道後面的代碼是錯誤,但這裏是什麼我正嘗試做一個例子:
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,在我的自定義控件的屬性窗口,我會喜歡看我的財產狀態,可以顯示它來設置屬性可見性和EventManagement。
非常感謝
馬克嗨,從來就進口System.ComponentModel命名空間使用TypeConverter屬性。我已經證明它並且工作正常。非常感謝! – Javier 2009-04-16 15:06:13