Export (0) Print
Expand All
3 out of 9 rated this helpful - Rate this topic

MessageBox Class

Displays a message box.

System.Object
  System.Windows.MessageBox

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
public sealed class MessageBox

The MessageBox type exposes the following members.

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberShow(String)Displays a message box that has a message and that returns a result.
Public methodStatic memberShow(String, String)Displays a message box that has a message and title bar caption; and that returns a result.
Public methodStatic memberShow(Window, String)Displays a message box in front of the specified window. The message box displays a message and returns a result.
Public methodStatic memberShow(String, String, MessageBoxButton)Displays a message box that has a message, title bar caption, and button; and that returns a result.
Public methodStatic memberShow(Window, String, String)Displays a message box in front of the specified window. The message box displays a message and title bar caption; and it returns a result.
Public methodStatic memberShow(String, String, MessageBoxButton, MessageBoxImage)Displays a message box that has a message, title bar caption, button, and icon; and that returns a result.
Public methodStatic memberShow(Window, String, String, MessageBoxButton)Displays a message box in front of the specified window. The message box displays a message, title bar caption, and button; and it also returns a result.
Public methodStatic memberShow(String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult)Displays a message box that has a message, title bar caption, button, and icon; and that accepts a default message box result and returns a result.
Public methodStatic memberShow(Window, String, String, MessageBoxButton, MessageBoxImage)Displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and it also returns a result.
Public methodStatic memberShow(String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult, MessageBoxOptions)Displays a message box that has a message, title bar caption, button, and icon; and that accepts a default message box result, complies with the specified options, and returns a result.
Public methodStatic memberShow(Window, String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult)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 and returns a result.
Public methodStatic memberShow(Window, String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult, MessageBoxOptions)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.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

For more information, see MessageBox Sample.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.