Use message box to display the messages in VB.NET

This article shows a message box that can contain text, buttons, and symbols to inform the user.
  • 23543

In this article we will discuss how to use message box to display the messages in windows forms in VB.NET.

Message box

Displays a message box that can contain text, buttons, and symbols to inform the user.

Message box class

Message box class are used for general message and user response.

1. general message

The simplest form of a MessageBox is a dialog with a text and OK button. The following code creates a simple MessageBox.

MessageBox.Show(string message, string caption, MessageBoxButtons b, MessageBoxIcon ic)

 

Example1-To display a simple message.

 

 

MessageBox.Show("Record has been updated")

 

m1.gif
 

 

Example2-To display a message with title.

MessageBox.Show("Record has been updated", "update")

m2.gif
 

Example3-Message box with caption and buttons.

MessageBoxButtons-specifies which buttons to display on a message box.

MessageBox.Show("Record has been updated", "update", MessageBoxButtons.YesNoCancel)

m3.gif
 

Example4-Message box with caption, buttons and icon.

MessageBox.Show("Record has been updated", "update", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Error)

m8.gif


 

2. Query message: To get response from the user.

Dialogresult- Dialog result are used to indicate the return value of a dialog box.

The following code creates a query mesage.

 

Dim ans As DialogResult = MessageBox.Show("Save the record", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)

        If ans = DialogResult.Yes Then

            MessageBox.Show("Yes clicked")

        ElseIf ans = DialogResult.No Then

            MessageBox.Show("No clicked")

        Else

            MessageBox.Show("Cancel clicked")

        End If


 

  m4.gif
 

Now click on the any button yes, no, cancel suppose we click on the yes button.

m8.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.