16,717
社区成员
发帖
与我相关
我的任务
分享
'在你的控件里声明如下属性
<TypeConverter(GetType(CDisplayFormatConvert))> _
<DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)> _
Property DisplayFormat() As CDisplayFormat
Get
Return _DisplayFormat
End Get
Set(ByVal value As CDisplayFormat)
_DisplayFormat = value
End Set
End Property
'编写如下类
Imports System.ComponentModel
Public Class CDisplayFormatConvert
Inherits TypeConverter
Public Overrides Function GetPropertiesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
Public Overrides Function GetProperties(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal value As Object, ByVal attributes() As System.Attribute) As System.ComponentModel.PropertyDescriptorCollection
Return TypeDescriptor.GetProperties(GetType(CDisplayFormat))
End Function
End Class
Imports System.ComponentModel
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
Public Class CDisplayFormat
Private _DisplayFormatString As String = "####0.##"
Private _Separator As String = ","
<NotifyParentPropertyAttribute(True)> _
<DefaultValue("####0.##")> _
Public Property FormatString() As String
Get
Return _DisplayFormatString
End Get
Set(ByVal value As String)
_DisplayFormatString = value
End Set
End Property
<NotifyParentPropertyAttribute(True)> _
<DefaultValue(",")> _
Public Property Separator() As String
Get
Return _Separator
End Get
Set(ByVal value As String)
_Separator = value
End Set
End Property
Public Overrides Function toString() As String
'这里返回的字符串是要在属性栏里显示的东西
Return "(DisplayFormat)"
End Function
End Class