|
发表于 2020-7-25 21:44:08
|
显示全部楼层
Public Class Form1
Dim tState As Boolean '开关
Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
tState = True
End Sub
Private Sub TextBox2_GotFocus(sender As Object, e As EventArgs) Handles TextBox2.GotFocus
tState = True
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
If TextBox1.Text = "" And tState Then
MsgBox("该项不能为空")
TextBox1.Focus()
End If
tState = False
End Sub
Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
If TextBox2.Text = "" And tState Then
MsgBox("该项不能为空")
TextBox2.Focus()
End If
tState = False
End Sub
End Class
'====================================
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If (Asc(e.KeyChar)) = 13 Then
If TextBox1.Text = "" Then MsgBox("不能为空!") : TextBox1.Focus()
End If
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
If TextBox1.Text = "" Then MsgBox("不能为空!") : TextBox1.Focus()
End Sub
|
|