2>这何检测字符占的像素值呀!<宽度>
3 个解决方案
#1
套嵌行不行?
#2
设立子属性呀,不知道怎么做。
学习。
学习。
#3
'
' 验证一个类似size的属性,by Montaque
'
Imports System.ComponentModel
Public Class MyControl111
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'UserControl1
'
Me.Name = "UserControl1"
End Sub
#End Region
Private mRange As New Range(11, 22)
Public Property RangeError() As Range
Get
Return mRange
End Get
Set(ByVal Value As Range)
mRange = Value
End Set
End Property
Public Property mysize() As Size
Get
End Get
Set(ByVal Value As Size)
End Set
End Property
'定一个class,调用TypeConverter特性
<TypeConverter(GetType(MyExpandableObjectConverter))> _
Public Class Range
Private strLow As String
Private strHigh As String
Sub New(ByVal low As String, ByVal high As String)
strLow = low
strHigh = high
End Sub
Sub New()
End Sub
Public Property Low() As String
Get
Return Me.strLow
End Get
Set(ByVal Value As String)
Me.strLow = Value
End Set
End Property
Public Property High() As String
Get
Return Me.strHigh
End Get
Set(ByVal Value As String)
Me.strHigh = Value
End Set
End Property
End Class
'自定一个转换格式
Public Class MyExpandableObjectConverter
Inherits ExpandableObjectConverter
Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
If sourceType Is GetType(String) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean
If destinationType Is GetType(Range) Then
Return True
End If
Return MyBase.CanConvertTo(context, destinationType)
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
If Not value Is Nothing Then
Try
Dim _Range As New Range
_Range.Low = value.ToString.Split(",")(0)
_Range.High = value.ToString.Split(",")(1)
Return _Range
Catch ex As Exception
MessageBox.Show("Error Occured While Trans Property")
End Try
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
If Not value Is Nothing Then
If destinationType Is GetType(String) Then
Dim _range As Range = CType(value, Range)
Return _range.Low & "," & _range.High
End If
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
End Class
End Class
#1
套嵌行不行?
#2
设立子属性呀,不知道怎么做。
学习。
学习。
#3
'
' 验证一个类似size的属性,by Montaque
'
Imports System.ComponentModel
Public Class MyControl111
Inherits System.Windows.Forms.UserControl
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'UserControl1 overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'UserControl1
'
Me.Name = "UserControl1"
End Sub
#End Region
Private mRange As New Range(11, 22)
Public Property RangeError() As Range
Get
Return mRange
End Get
Set(ByVal Value As Range)
mRange = Value
End Set
End Property
Public Property mysize() As Size
Get
End Get
Set(ByVal Value As Size)
End Set
End Property
'定一个class,调用TypeConverter特性
<TypeConverter(GetType(MyExpandableObjectConverter))> _
Public Class Range
Private strLow As String
Private strHigh As String
Sub New(ByVal low As String, ByVal high As String)
strLow = low
strHigh = high
End Sub
Sub New()
End Sub
Public Property Low() As String
Get
Return Me.strLow
End Get
Set(ByVal Value As String)
Me.strLow = Value
End Set
End Property
Public Property High() As String
Get
Return Me.strHigh
End Get
Set(ByVal Value As String)
Me.strHigh = Value
End Set
End Property
End Class
'自定一个转换格式
Public Class MyExpandableObjectConverter
Inherits ExpandableObjectConverter
Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
If sourceType Is GetType(String) Then
Return True
End If
Return MyBase.CanConvertFrom(context, sourceType)
End Function
Public Overloads Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean
If destinationType Is GetType(Range) Then
Return True
End If
Return MyBase.CanConvertTo(context, destinationType)
End Function
Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
If Not value Is Nothing Then
Try
Dim _Range As New Range
_Range.Low = value.ToString.Split(",")(0)
_Range.High = value.ToString.Split(",")(1)
Return _Range
Catch ex As Exception
MessageBox.Show("Error Occured While Trans Property")
End Try
End If
Return MyBase.ConvertFrom(context, culture, value)
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
If Not value Is Nothing Then
If destinationType Is GetType(String) Then
Dim _range As Range = CType(value, Range)
Return _range.Low & "," & _range.High
End If
End If
Return MyBase.ConvertTo(context, culture, value, destinationType)
End Function
End Class
End Class