Vb. NET to confirm the Exit dialog box implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.