다음을 통해 공유


MessageBox.Show Method (String, String, MessageBoxButton)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Shared Function Show ( _
    messageBoxText As String, _
    caption As String, _
    button As MessageBoxButton _
) As MessageBoxResult
public static MessageBoxResult Show(
    string messageBoxText,
    string caption,
    MessageBoxButton button
)

Parameters

Return Value

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

Exceptions

Exception Condition
ArgumentNullException

messageBoxText is nulla null reference (Nothing in Visual Basic).

-or-

caption is nulla null reference (Nothing in Visual Basic).

ArgumentException

button is not a valid MessageBoxButton value.

Remarks

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.

Examples

The following example code demonstrates how to use this method.

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

If (result = MessageBoxResult.OK) Then
    MessageBox.Show("No caption, one button.")
End If
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.");
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

Platforms

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