A message box is a prefabricated modal dialog box that displays a text message to a user. You show a message box by calling the static Show method of the MessageBox class. The text message that is displayed is the string argument that you pass to Show. Several overloads of the Show method also enables you to provide a title bar caption.
To enable a user to close a message box, Show displays a message box that has an OK button and a Close button in the title bar.
You can also use a message box to ask a user a question. The user answers by clicking one of several buttons that you specify to display by using the MessageBoxButton enumeration. You can pass this enumeration to several overloads of the Show method. The default value of the MessageBoxButton enumeration is OK.
You can determine which button a user clicks by examining the value that Show returns. The return value is a value of the MessageBoxResult enumeration, where each value equates to one of the buttons that a message box can display. The default value for message box is OK because OK is the default message box button. However, some overloads of the Show method enable you to provide a different MessageBoxResult default value.
Message boxes can communicate information and can ask questions that have varying degrees of importance. Message boxes use icons to indicate importance. For example, icons can indicate whether the message is informational, is a warning, or is important. The MessageBoxImage enumeration encapsulates the set of possible message box icons. By default, a message box does not display an icon. However, you can pass a MessageBoxImage value to one of several Show method overloads in order to specify that the message box includes an icon.
Message boxes sometimes provide special functionality, such as right-to-left reading. You can customize the behavior of a message box by using one or more MessageBoxOptions enumeration values that are accepted by some overloads of the Show method.
Message boxes always have an owner window. By default, the owner of a message box is the window that is currently active in an application at the time that a message box is opened. However, you can specify another owner for the Window by using one of several Show overloads. For more information about owner windows, see Window.Owner.
Displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and accepts a default message box result, complies with the specified options, and returns a result.