5 out of 6 rated this helpful - Rate this topic

MessageBox Class

Displays a message box.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
public sealed class MessageBox
You cannot directly create an instance of this class in XAML.

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.

See MessageBox Sample.

System.Object
  System.Windows.MessageBox
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.