WPF 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.
  • 1908

In this article we will discuss how to use message box to display the messages in WPF using 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, MessageBoxButton b, MessageBoxImage ic)


Example1-To display a simple message.



MessageBox.Show("Record has been updated")



Figure 1.


Example2-To display a message with title.

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

Figure 2.

Example3-Message box with caption and buttons.

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

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

Figure 3.

Example4-Message box with caption, buttons and icon.

MessageBox.Show("Record has been updated""update"MessageBoxButton.YesNoCancel,MessageBoxImage.Error)

Figure 4.

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

MessageBoxResult MessageBoxResult are used to indicate the return value of a dialog box.

The following code creates a query message.

Dim ans As MessageBoxResult = MessageBox.Show("Save the record""Save",MessageBoxButton.YesNoCancel, MessageBoxImage.Question)

        If ans = MessageBoxResult.Yes Then

            MessageBox.Show("Yes clicked")

        ElseIf ans = MessageBoxResult.No Then

            MessageBox.Show("No clicked")


            MessageBox.Show("Cancel clicked")

        End If

    End Sub



Figure 5.

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

Figure 6.


More Articles

© 2018 DotNetHeaven. All rights reserved.