# 应该像这样做

Posted by cww on April 19, 1999 at 16:04:33:

In Reply to: Re: 这是讨厌的问题:validate 好像也不可以 posted by 小飞虾 on April 19, 1999 at 14:55:11:

是设定Validate中Cancel=True来防止Focus的移转，而
不是用SetFocus来指回自己，所以由Text1 按Tab到
Text2时，只要Text1.text = ""，Text2.GotFocus是不
会执行的

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub

Private Sub Text1_Validate(Cancel As Boolean)
If Text1.Text = "" Then
Cancel = True
End If
End Sub

Private Sub Text2_Validate(Cancel As Boolean)
If Text2.Text = "" Then
Cancel = True
End If
End Sub

Follow Ups: