Implementation of the confirm exit dialog box in VB. NET

Source: Internet
Author: User

When coding, We Need To prompt users before they exit the system for a more user-friendly design, such:

The implementation methods are divided into two categories: Form Events and control events, which are shown as follows:

I. formclosing event (several methods are described below)

A.

Private sub frmpractise_formclosing (byval sender as object, byval e as system. Windows. Forms. formclosingeventargs) handles me. formclosing if MessageBox. Show ("are you sure you want to exit? "," Exit confirmation ", messageboxbuttons. yesno, messageboxicon. Question) = windows. Forms. dialogresult. No then E. Cancel = true 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 ("are you sure you want 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 exit the system? ", Msgboxstyle. okcancel," prompt ") if p = 2 then E. Cancel = true end if end sub

D. (simplest)

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 exit the program? ", Msgboxstyle. okcancel," Exit prompt ") = msgboxresult. Cancel then E. Cancel = true end sub

 

The above is just the usage when you click the close button in the window. If you click exit on the Form Control directly, you can use the following method to achieve it:

 

Ii. 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," prompt ") = msgboxresult. yes then application. Exit () end if end sub

 

 

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.