The implementation methods are divided into two main categories: Form events and control events, the following one by one shows: First, formclosing events (and several other methods)
A.
Private Sub frmpractise_formclosing (ByVal sender as Object, ByVal e as System.Windows.Forms.FormClosingEventArgs) Handles me.formclosing If MessageBox.Show ("OK to exit?") "," Exit confirmation ", Messageboxbuttons.yesno, messageboxicon.question) = Windows.Forms.DialogResult.No then e.cancel = true< C2/>end If End Sub
B.
Private Sub practise_formclosing (ByVal sender as Object, ByVal e as System.Windows.Forms.FormClosingEventArgs) Handles Me . FormClosing If MsgBox ("OK to exit?") ", Messageboxbuttons.okcancel," exit confirmation ") = Windows.Forms.DialogResult.Cancel then e.cancel = True end If End Sub
C.
Private Sub practise_formclosing (ByVal sender as Object, ByVal e as System.Windows.Forms.FormClosingEventArgs) Handles Me . FormClosing Dim p as Integer p = MsgBox ("Do you really want to quit the system?") ", Msgboxstyle.okcancel," hint ") if P = 2 then e.cancel = True end If End Sub
D. (Most simple)
Private Sub practise_formclosing (ByVal sender as Object, ByVal e as System.Windows.Forms.FormClosingEventArgs) Handles Me . FormClosing If MsgBox ("Are you sure you want to quit the program?") ", Msgboxstyle.okcancel," exit hint ") = Msgboxresult.cancel then E.cancel = True End Sub
The above is just the use of clicking the window Close button, if you click Exit directly on the form control, you can do the following: Second, Button_Click event
Private Sub Btnquit_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Btnquit.click If MsgBox ( "Do you want to exit the system?" ", Msgboxstyle.yesno + msgboxstyle.question," hint ") = Msgboxresult.yes then application.exit () end If End Sub
Vb. NET to confirm the Exit dialog box implementation