MessageBox.Show Method

Definition

Displays a message box.

Overloads

Show(String)

Displays a message box that has a message and that returns a result.

Show(String, String)

Displays a message box that has a message and title bar caption; and that returns a result.

Show(Window, String)

Displays a message box in front of the specified window. The message box displays a message and returns a result.

Show(String, String, MessageBoxButton)

Displays a message box that has a message, title bar caption, and button; and that returns a result.

Show(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.

Show(String, String, MessageBoxButton, MessageBoxImage)

Displays a message box that has a message, title bar caption, button, and icon; and that returns a result.

Show(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.

Show(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.

Show(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.

Show(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.

Show(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.

Show(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.

Remarks

Use an overload of the Show method, which enables you to specify an owner window. Otherwise, the message box is owned by the window that is currently active.

Show(String)

Displays a message box that has a message and that returns a result.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText);
C#
public static System.Windows.MessageBoxResult Show(string messageBoxText);

Parameters

messageBoxText
String

A String that specifies the text to display.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Examples

The following example shows how to use this overload of the Show method.

C#
private void ShowMessageBoxButton_Click(object sender, RoutedEventArgs e)
{
    // Configure message box
    string message = "Hello, MessageBox!";
    // Show message box
    MessageBoxResult result = MessageBox.Show(message);
}

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(String, String)

Displays a message box that has a message and title bar caption; and that returns a result.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption);
C#
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption);

Parameters

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Examples

The following example shows how to use this overload of the Show method.

C#
private void ShowMessageBoxButton_Click(object sender, RoutedEventArgs e)
{
    // Configure message box
    string message = "Message text";
    string caption = "Caption text";
    // Show message box
    MessageBoxResult result = MessageBox.Show(message, caption);
}

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(Window, String)

Displays a message box in front of the specified window. The message box displays a message and returns a result.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText);
C#
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText);

Parameters

owner
Window

A Window that represents the owner window of the message box.

messageBoxText
String

A String that specifies the text to display.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Remarks

By default, the message box appears in front of the window that is currently active.

See also

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(String, String, MessageBoxButton)

Displays a message box that has a message, title bar caption, and button; and that returns a result.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button);
C#
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button);

Parameters

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

button
MessageBoxButton

A MessageBoxButton value that specifies which button or buttons to display.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Examples

The following example shows how to use this overload of the Show method.

C#
private void ShowMessageBoxButton_Click(object sender, RoutedEventArgs e)
{
    // Configure message box
    string message = "Hello, MessageBox!";
    string caption = "Caption text";
    MessageBoxButton buttons = MessageBoxButton.OKCancel;
    // Show message box
    MessageBoxResult result = MessageBox.Show(message, caption, buttons);
}

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(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.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption);
C#
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption);

Parameters

owner
Window

A Window that represents the owner window of the message box.

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Remarks

By default, the message box appears in front of the window that is currently active.

See also

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(String, String, MessageBoxButton, MessageBoxImage)

Displays a message box that has a message, title bar caption, button, and icon; and that returns a result.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon);
C#
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon);

Parameters

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

button
MessageBoxButton

A MessageBoxButton value that specifies which button or buttons to display.

icon
MessageBoxImage

A MessageBoxImage value that specifies the icon to display.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Examples

The following example shows how to use this overload of the Show method.

C#
private void ShowMessageBoxButton_Click(object sender, RoutedEventArgs e)
{
    // Configure message box
    string message = "Hello, MessageBox!";
    string caption = "Caption text";
    MessageBoxButton buttons = MessageBoxButton.OKCancel;
    MessageBoxImage icon = MessageBoxImage.Information;
    // Show message box
    MessageBoxResult result = MessageBox.Show(message, caption, buttons, icon);
}

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(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.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button);
C#
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button);

Parameters

owner
Window

A Window that represents the owner window of the message box.

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

button
MessageBoxButton

A MessageBoxButton value that specifies which button or buttons to display.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Remarks

By default, the message box appears in front of the window that is currently active.

See also

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(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.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult);
C#
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult);

Parameters

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

button
MessageBoxButton

A MessageBoxButton value that specifies which button or buttons to display.

icon
MessageBoxImage

A MessageBoxImage value that specifies the icon to display.

defaultResult
MessageBoxResult

A MessageBoxResult value that specifies the default result of the message box.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Examples

The following example shows how to use this overload of the Show method.

C#
private void ShowMessageBoxButton_Click(object sender, RoutedEventArgs e)
{
    // Configure message box
    string message = "Hello, MessageBox!";
    string caption = "Caption text";
    MessageBoxButton buttons = MessageBoxButton.OKCancel;
    MessageBoxImage icon = MessageBoxImage.Information;
    MessageBoxResult defaultResult = MessageBoxResult.OK;
    // Show message box
    MessageBoxResult result = MessageBox.Show(message, caption, buttons, icon, defaultResult);
}

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(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.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon);
C#
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon);

Parameters

owner
Window

A Window that represents the owner window of the message box.

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

button
MessageBoxButton

A MessageBoxButton value that specifies which button or buttons to display.

icon
MessageBoxImage

A MessageBoxImage value that specifies the icon to display.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Remarks

By default, the message box appears in front of the window that is currently active.

See also

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(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.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult, System.Windows.MessageBoxOptions options);
C#
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult, System.Windows.MessageBoxOptions options);

Parameters

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

button
MessageBoxButton

A MessageBoxButton value that specifies which button or buttons to display.

icon
MessageBoxImage

A MessageBoxImage value that specifies the icon to display.

defaultResult
MessageBoxResult

A MessageBoxResult value that specifies the default result of the message box.

options
MessageBoxOptions

A MessageBoxOptions value object that specifies the options.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Examples

The following example shows how to use this overload of the Show method.

C#
private void ShowMessageBoxButton_Click(object sender, RoutedEventArgs e)
{
    // Configure message box
    string message = "Hello, MessageBox!";
    string caption = "Caption text";
    MessageBoxButton buttons = MessageBoxButton.OKCancel;
    MessageBoxImage icon = MessageBoxImage.Information;
    MessageBoxResult defaultResult = MessageBoxResult.OK;
    MessageBoxOptions options = MessageBoxOptions.RtlReading;
    // Show message box
    MessageBoxResult result = MessageBox.Show(message, caption, buttons, icon, defaultResult, options);
}

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(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.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult);
C#
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult);

Parameters

owner
Window

A Window that represents the owner window of the message box.

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

button
MessageBoxButton

A MessageBoxButton value that specifies which button or buttons to display.

icon
MessageBoxImage

A MessageBoxImage value that specifies the icon to display.

defaultResult
MessageBoxResult

A MessageBoxResult value that specifies the default result of the message box.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Remarks

By default, the message box appears in front of the window that is currently active.

See also

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Show(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.

C#
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult, System.Windows.MessageBoxOptions options);
C#
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult, System.Windows.MessageBoxOptions options);

Parameters

owner
Window

A Window that represents the owner window of the message box.

messageBoxText
String

A String that specifies the text to display.

caption
String

A String that specifies the title bar caption to display.

button
MessageBoxButton

A MessageBoxButton value that specifies which button or buttons to display.

icon
MessageBoxImage

A MessageBoxImage value that specifies the icon to display.

defaultResult
MessageBoxResult

A MessageBoxResult value that specifies the default result of the message box.

options
MessageBoxOptions

A MessageBoxOptions value object that specifies the options.

Returns

A MessageBoxResult value that specifies which message box button is clicked by the user.

Attributes

Remarks

By default, the message box appears in front of the window that is currently active.

See also

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10