Export (0) Print
Expand All

MessageBox.Show Method (String, String, MessageBoxButton)

Displays a message box that contains the specified text, title bar caption, and response buttons.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public static MessageBoxResult Show(
	string messageBoxText,
	string caption,
	MessageBoxButton button
)

Parameters

messageBoxText
Type: System.String
The message to display.
caption
Type: System.String
The title of the message box.
button
Type: System.Windows.MessageBoxButton
A value that indicates the button or buttons to display.

Return Value

Type: System.Windows.MessageBoxResult
A value that indicates the user's response to the message.

ExceptionCondition
ArgumentNullException

messageBoxText is null.

-or-

caption is null.

ArgumentException

button is not a valid MessageBoxButton value.

The message box is modal, which means that the user must click a button or press ESC to dismiss the message.

If the button parameter is OK, then the return value is OK in all cases.

If the button parameter is OKCancel, then the return value is OK only when the user has clicked the OK button. Otherwise, the return value is Cancel.

The following example code demonstrates how to use this method.


MessageBoxResult result = 
    MessageBox.Show("Would you like to see the simple version?", 
    "MessageBox Example", MessageBoxButton.OKCancel);

if (result == MessageBoxResult.OK)
{
    MessageBox.Show("No caption, one button.");
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft