📄 myvalidatingtextbox.vb
字号:
Imports System.Text.RegularExpressions
Public Class MyValidatingTextBox
Inherits System.Windows.Forms.TextBox
Protected _ErrorMessage As String
Public Property ErrorMessage() As String
Get
Return _ErrorMessage
End Get
Set(ByVal Value As String)
_ErrorMessage = Value
End Set
End Property
Protected _ErrorColor As Color = Color.Red
Public Property ErrorColor() As Color
Get
Return _ErrorColor
End Get
Set(ByVal Value As Color)
_ErrorColor = Value
End Set
End Property
Public ReadOnly Property IsValid() As Boolean
Get
If Not _Regex1 Is Nothing Then
Return _Regex1.IsMatch(Me.Text)
Else
Return True
End If
End Get
End Property
Protected _ValidationExpression As String
Protected _Regex1 As Regex
Public Property ValidationExpression() As String
Get
Return _ValidationExpression
End Get
Set(ByVal Value1 As String)
If Value1 Is Nothing Then Value1 = "^\d{3}$"
_Regex1 = New Regex(Value1)
_ValidationExpression = Value1
End Set
End Property
Protected Overrides Sub OnValidated(ByVal e As System.EventArgs)
If Not Me.IsValid Then
Me.ForeColor = _ErrorColor
Else
Me.ForeColor = Me.DefaultForeColor
End If
MyBase.OnValidated(e)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -