WPF MessageBox in VB.NET

This article shows how to use a MessageBox control in WPF and VB.NET.
  • 5979
MessageBox Dialog

A message box is a dialog box that is used to display an alert or a message or also let the user have some options to choose from. A simple message box has an OK button and looks like Figure 1.

 

figure1.JPG 


Figure 1

 

A message box can have a title and multiple options such as Yes, No, and Cancel. A message box can also have some input control to take input from a user.

 

The MessageBox class in WPF represents a modal message box dialog, which is defined in the System.Windows namespace. The Show static method of the MessageBox is the only useful method that is used to display a message box. The following line of code uses Show method to display a message box with a simple message.

 

MessageBox.Show("Hello MessageBox!")

 

The Show method returns a MessageBoxResult enumeration, which has following values.

  • Yes

  • No

  • OK

  • Cancel

  • None

The following code snippet checks if the Show method returns OK then do something.

 

If  MessageBox.Show("Hello MessageBox!") = MessageBoxResult.OK Then

' Do something


End If

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.