Form closing (save changes?) code...? (RESOLVED)
I'm using the following code:
VB Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If Text.EndsWith("*") = False Then Text = Text & "*"
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
If Text.EndsWith("*") = False Then Text = Text & "*"
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Text.EndsWith("*") Then
Select Case MsgBox("Would you like to save the changes?", MsgBoxStyle.Question + MsgBoxStyle.YesNoCancel + MsgBoxStyle.DefaultButton3)
Case MsgBoxResult.Yes : SaveChangesSub
Case MsgBoxResult.Cancel : e.Cancel = True
End Select
End If
End Sub
The problems are:
- When we press the control or Alt or CapsLock or Shift button the Form1_KeyDown is fired;
- When we click on a button it isn't fired;
- When we change a combo's item isn't fired.
How to improve it? Is there a way to write a simple code or I'll have to add the "*" cade in every single control?
Thanks.