7,765
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Activate()
Text1.SetFocus
End Sub
Private Sub Form_Load()
Command1.Caption = "E&xit"
Command1.CausesValidation = False
End Sub
Private Sub Text1_Validate(Cancel As Boolean)
If Text1 <> "1234" Then Cancel = True
End Sub
另一种做法是去掉 Form_Activate 事件,在 Formload 中设置 Text1 的 TabIndex = 0:Private Sub Form_Load()
Command1.Caption = "E&xit"
Command1.CausesValidation = False
Text1.TabIndex = 0
End Sub
Private sub Form_Load()
Me.Show
Text1.SetFocus
End Sub
Private sub Text1_LostFocus()
If Text1.Text <> "测试正确" Then Text1.SetFocu
End Sub