ARTICLE

Messagebox with Yes/No buttons in VB.NET

Posted by Hirendra Sisodiya Articles | Visual Basic 2010 July 23, 2010
In this article you will learn how to use messagebox with Yes/No buttons in vb.net.
 
Reader Level:

We are very familiar with messagebox class, this is widely used in any application .net framework provides various ways for using messagebox in application.

We have been using messagebox in very simple ways like

Messagebox.show("hello this is vb.net application")

But we can use messagebox with different –different styles such as messagebox with predefined icon,messagebox with multiple buttons like Yes,No,abort……

In this article we will discuss messagebox with multiple buttons in brief.

Suppose in our application there is one form with some textboxs and values of these textboxes filled on the basis of unique id from database now user can change some values of textbox(s), and want to close this form. you want to display a message 'Do you want to save data before closing this form'  with Yes and No button. User can select yes or No button.

Messagebox.JPG


We can do that like this:

Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

        If (MessageBox.Show("Do you want to save data before closing this form", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) = Windows.Forms.DialogResult.Yes Then

            ' Update query

        Else

            Me.Close()

        End If

     End Sub

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Diagram
Become a Sponsor