我用下面的代码来验证,如果文本到文本框被改变,并要求保存更改: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