Imports System.Text.RegularExpressions
Public Class RegexedTextBox
Inherits TextBox
Private MyPattern As String = "^.*$"
Private MyErrorColor As Color = Color.Red
Private MyNormalColor As Color = Color.White
Public Property Pattern As String
Get
Return MyPattern
End Get
Set(ByVal value As String)
MyPattern = value
Me.BackColor = If(IsValid, NormalColor, ErrorColor)
End Set
End Property
Public Property ErrorColor As Color
Get
Return MyErrorColor
End Get
Set(ByVal value As Color)
MyErrorColor = value
Me.BackColor = If(IsValid, NormalColor, ErrorColor)
End Set
End Property
Public Property NormalColor As Color
Get
Return MyNormalColor
End Get
Set(ByVal value As Color)
MyNormalColor = value
Me.BackColor = If(IsValid, NormalColor, ErrorColor)
End Set
End Property
Public ReadOnly Property IsValid As Boolean
Get
Return Regex.IsMatch(Me.Text, Pattern)
End Get
End Property
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
Me.BackColor = If(IsValid, NormalColor, ErrorColor)
MyBase.OnTextChanged(e)
End Sub
End Class
Сейчас этот форум просматривают: Google-бот и гости: 91