📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
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
Private components As System.ComponentModel.IContainer
Friend WithEvents MyValidatingTextBox1 As Validating.MyValidatingTextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents MyValidatingTextBox2 As Validating.MyValidatingTextBox
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents MyValidatingTextBox3 As Validating.MyValidatingTextBox
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents MyValidatingEmailTextBox1 As Validating.MyValidatingEmailTextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MyValidatingTextBox1 = New Validating.MyValidatingTextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.MyValidatingTextBox2 = New Validating.MyValidatingTextBox()
Me.Button4 = New System.Windows.Forms.Button()
Me.MyValidatingTextBox3 = New Validating.MyValidatingTextBox()
Me.Button5 = New System.Windows.Forms.Button()
Me.MyValidatingEmailTextBox1 = New Validating.MyValidatingEmailTextBox()
Me.SuspendLayout()
'
'MyValidatingTextBox1
'
Me.MyValidatingTextBox1.ErrorColor = System.Drawing.Color.Red
Me.MyValidatingTextBox1.ErrorMessage = Nothing
Me.MyValidatingTextBox1.Location = New System.Drawing.Point(31, 24)
Me.MyValidatingTextBox1.Name = "MyValidatingTextBox1"
Me.MyValidatingTextBox1.Size = New System.Drawing.Size(215, 21)
Me.MyValidatingTextBox1.TabIndex = 0
Me.MyValidatingTextBox1.Text = "123"
Me.MyValidatingTextBox1.ValidationExpression = "^\d{3}$"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(276, 24)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(154, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "验证输入3个数字"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(276, 136)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(154, 24)
Me.Button2.TabIndex = 3
Me.Button2.Text = "验证输入E-Mail"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(276, 56)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(154, 24)
Me.Button3.TabIndex = 5
Me.Button3.Text = "验证输入电话号码"
'
'MyValidatingTextBox2
'
Me.MyValidatingTextBox2.ErrorColor = System.Drawing.Color.Red
Me.MyValidatingTextBox2.ErrorMessage = Nothing
Me.MyValidatingTextBox2.Location = New System.Drawing.Point(31, 56)
Me.MyValidatingTextBox2.Name = "MyValidatingTextBox2"
Me.MyValidatingTextBox2.Size = New System.Drawing.Size(215, 21)
Me.MyValidatingTextBox2.TabIndex = 4
Me.MyValidatingTextBox2.Text = "(035) 1234-5678"
Me.MyValidatingTextBox2.ValidationExpression = "^\d{3}$"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(276, 88)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(154, 24)
Me.Button4.TabIndex = 7
Me.Button4.Text = "验证输入IP地址"
'
'MyValidatingTextBox3
'
Me.MyValidatingTextBox3.ErrorColor = System.Drawing.Color.Red
Me.MyValidatingTextBox3.ErrorMessage = Nothing
Me.MyValidatingTextBox3.Location = New System.Drawing.Point(31, 88)
Me.MyValidatingTextBox3.Name = "MyValidatingTextBox3"
Me.MyValidatingTextBox3.Size = New System.Drawing.Size(215, 21)
Me.MyValidatingTextBox3.TabIndex = 6
Me.MyValidatingTextBox3.Text = "111.111.111.111"
Me.MyValidatingTextBox3.ValidationExpression = "^\d{3}$"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(276, 192)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(154, 24)
Me.Button5.TabIndex = 8
Me.Button5.Text = "验证所有输入"
'
'MyValidatingEmailTextBox1
'
Me.MyValidatingEmailTextBox1.ErrorColor = System.Drawing.Color.Red
Me.MyValidatingEmailTextBox1.ErrorMessage = "E-mail格式为abc@xxx.yyy.zz 或者abc@xxx.yyy !"
Me.MyValidatingEmailTextBox1.Location = New System.Drawing.Point(31, 136)
Me.MyValidatingEmailTextBox1.Name = "MyValidatingEmailTextBox1"
Me.MyValidatingEmailTextBox1.Size = New System.Drawing.Size(215, 21)
Me.MyValidatingEmailTextBox1.TabIndex = 9
Me.MyValidatingEmailTextBox1.Text = "abc@xxx.yyy.zz"
Me.MyValidatingEmailTextBox1.ValidationExpression = "^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0" & _
"-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-" & _
"9][0-9]|[1-9][0-9]|[0-9])\])$"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(460, 238)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.MyValidatingEmailTextBox1, Me.Button5, Me.Button4, Me.MyValidatingTextBox3, Me.Button3, Me.MyValidatingTextBox2, Me.Button2, Me.Button1, Me.MyValidatingTextBox1})
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "自己设计的工具箱组件[输入验证TextBox]"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyValidatingTextBox1.ValidationExpression = "^\d{3}$"
MyValidatingTextBox1.ErrorMessage = "应该输入3个数字!"
MyValidatingTextBox2.ValidationExpression = "^((\(\d{3}\) ?)|(\d{3}-))?\d{4}-\d{4}$"
MyValidatingTextBox2.ErrorMessage = "电话号码格式 (035) 1234-5678 !"
MyValidatingTextBox3.ValidationExpression = "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$"
MyValidatingTextBox3.ErrorMessage = "I格式 111.111.111.111"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Not MyValidatingTextBox1.IsValid Then
MsgBox(MyValidatingTextBox1.ErrorMessage)
Else
MsgBox("验证正确!")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Not MyValidatingEmailTextBox1.IsValid Then
MsgBox(MyValidatingEmailTextBox1.ErrorMessage)
Else
MsgBox("验证正确!")
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Not MyValidatingTextBox2.IsValid Then
MsgBox(MyValidatingTextBox2.ErrorMessage)
Else
MsgBox("验证正确!")
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Not MyValidatingTextBox3.IsValid Then
MsgBox(MyValidatingTextBox3.ErrorMessage)
Else
MsgBox("验证正确!")
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim ctl1 As Control
Dim msg1 As String
For Each ctl1 In Controls
If TypeOf ctl1 Is MyValidatingTextBox Then
Dim MyTextBox As MyValidatingTextBox = CType(ctl1, MyValidatingTextBox)
If Not MyTextBox.IsValid Then
msg1 &= MyTextBox.Name & ":" & MyTextBox.ErrorMessage & vbCrLf
End If
End If
Next
If msg1 <> "" Then
MsgBox(msg1)
Else
MsgBox("验证正确!")
End If
End Sub
Private Sub MyValidatingEmailTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyValidatingEmailTextBox1.TextChanged
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -