我用下面的代碼來驗證,如果文本到文本框被改變,並要求保存更改:Button.Click事件TextBox.Leave事件後不火
Private TBoxTxtBefore As String = String.Empty
Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter
Try
TBoxTxtBefore = CType(sender, TextBox).Text
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
Try
If CType(sender, TextBox).Text <> TBoxTxtBefore Then
Dim SN As MsgBoxResult = MsgBox("Save changes?", vbYesNo, "Save Changes")
If SN = vbYes Then Btn_SaveChanges.PerformClick()
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
但是當我點擊一個按鈕(例如button1
),而光標位於TextBox1
內部時,只會引發TextBox1.Leave
事件。
我怎麼能有TextBox1.Leave
事件之後Button?.click
事件提高?
編輯這個問題,並顯示Button1的Click事件以及Btn_SaveChanges單擊事件。 – dbasnett