Imports System.ComponentModel Public Class NumberText Inherits RestrictText Public Property FormatString As String = "#,0.000" Public Property IntegerLength As Integer = 5 '整数部の桁数 Public Property DecimalLength As Integer = 3 '小数部の桁数 Private Shared ReadOnly allowChars As New HashSet(Of Char)("0123456789.-".ToArray()) Protected Overrides Function IsAllowChar(inputChar As Char) As Boolean Return allowChars.Contains(inputChar) End Function Protected Overrides Function IsValidText(reflectsText As String) As Boolean If String.IsNullOrEmpty(reflectsText) Then Return True End If Dim dec As Decimal If Not Decimal.TryParse(reflectsText, dec) Then Return False End If reflectsText = reflectsText.Replace("-", "") Dim pos As Integer = reflectsText.IndexOf(".") Dim ilen As Integer Dim dlen As Integer If pos = -1 Then ilen = reflectsText.Length dlen = 0 Else ilen = pos dlen = reflectsText.Length - pos - 1 End If If ilen > IntegerLength OrElse dlen > DecimalLength Then Return False End If Return MyBase.IsValidText(reflectsText) End Function Protected Overrides Function Format(value As String) As String Dim dec As Decimal If Decimal.TryParse(value, dec) Then Return dec.ToString(FormatString) Else Return value End If End Function <Browsable(False)> <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> Public Property Value As Decimal Get Dim dec As Decimal If Decimal.TryParse(Text, dec) Then Return dec Else Return 0 End If End Get Set(value As Decimal) Text = value.ToString(FormatString) End Set End Property End Class