MessageBox.Show 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
显示消息框。
重载
注解
使用方法的 Show 重载,使你能够指定所有者窗口。 否则,消息框由当前处于活动状态的窗口拥有。
Show(String)
显示一个消息框,其中包含一条消息并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::String ^ messageBoxText);
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText);
public static System.Windows.MessageBoxResult Show(string messageBoxText);
[<System.Security.SecurityCritical>]
static member Show : string -> System.Windows.MessageBoxResult
static member Show : string -> System.Windows.MessageBoxResult
Public Shared Function Show (messageBoxText As String) As MessageBoxResult
参数
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
示例
以下示例演示如何使用此方法重 Show 载。
private void ShowMessageBoxButton_Click(object sender, RoutedEventArgs e)
{
// Configure message box
string message = "Hello, MessageBox!";
// Show message box
MessageBoxResult result = MessageBox.Show(message);
}
Private Sub showMessageBoxButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Configure message box
Dim message As String = "Hello, MessageBox!"
' Show message box
Dim result As MessageBoxResult = MessageBox.Show(message)
End Sub
适用于
Show(String, String)
显示包含消息和标题栏标题的消息框;并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::String ^ messageBoxText, System::String ^ caption);
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption);
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption);
[<System.Security.SecurityCritical>]
static member Show : string * string -> System.Windows.MessageBoxResult
static member Show : string * string -> System.Windows.MessageBoxResult
Public Shared Function Show (messageBoxText As String, caption As String) As MessageBoxResult
参数
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
示例
以下示例演示如何使用此方法重 Show 载。
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);
}
Private Sub showMessageBoxButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Configure message box
Dim message As String = "Message text"
Dim caption As String = "Caption text"
' Show message box
Dim result As MessageBoxResult = MessageBox.Show(message, caption)
End Sub
适用于
Show(Window, String)
在指定窗口前面显示一个消息框。 消息框显示消息并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::Windows::Window ^ owner, System::String ^ messageBoxText);
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText);
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText);
[<System.Security.SecurityCritical>]
static member Show : System.Windows.Window * string -> System.Windows.MessageBoxResult
static member Show : System.Windows.Window * string -> System.Windows.MessageBoxResult
Public Shared Function Show (owner As Window, messageBoxText As String) As MessageBoxResult
参数
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
注解
默认情况下,消息框显示在当前处于活动状态的窗口前面。
另请参阅
适用于
Show(String, String, MessageBoxButton)
显示一个消息框,其中包含消息、标题栏标题和按钮;并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::String ^ messageBoxText, System::String ^ caption, System::Windows::MessageBoxButton button);
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button);
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button);
[<System.Security.SecurityCritical>]
static member Show : string * string * System.Windows.MessageBoxButton -> System.Windows.MessageBoxResult
static member Show : string * string * System.Windows.MessageBoxButton -> System.Windows.MessageBoxResult
Public Shared Function Show (messageBoxText As String, caption As String, button As MessageBoxButton) As MessageBoxResult
参数
- button
- MessageBoxButton
一个 MessageBoxButton 值,指定要显示的按钮或按钮。
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
示例
以下示例演示如何使用此方法重 Show 载。
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);
}
Private Sub showMessageBoxButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Configure message box
Dim message As String = "Hello, MessageBox!"
Dim caption As String = "Caption text"
Dim buttons As MessageBoxButton = MessageBoxButton.OKCancel
' Show message box
Dim result As MessageBoxResult = MessageBox.Show(message, caption, buttons)
End Sub
适用于
Show(Window, String, String)
在指定窗口前面显示一个消息框。 消息框显示消息和标题栏标题;并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::Windows::Window ^ owner, System::String ^ messageBoxText, System::String ^ caption);
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption);
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption);
[<System.Security.SecurityCritical>]
static member Show : System.Windows.Window * string * string -> System.Windows.MessageBoxResult
static member Show : System.Windows.Window * string * string -> System.Windows.MessageBoxResult
Public Shared Function Show (owner As Window, messageBoxText As String, caption As String) As MessageBoxResult
参数
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
注解
默认情况下,消息框显示在当前处于活动状态的窗口前面。
另请参阅
适用于
Show(String, String, MessageBoxButton, MessageBoxImage)
显示一个消息框,其中包含消息、标题栏标题、按钮和图标;并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::String ^ messageBoxText, System::String ^ caption, System::Windows::MessageBoxButton button, System::Windows::MessageBoxImage icon);
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon);
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon);
[<System.Security.SecurityCritical>]
static member Show : string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage -> System.Windows.MessageBoxResult
static member Show : string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage -> System.Windows.MessageBoxResult
Public Shared Function Show (messageBoxText As String, caption As String, button As MessageBoxButton, icon As MessageBoxImage) As MessageBoxResult
参数
- button
- MessageBoxButton
一个 MessageBoxButton 值,指定要显示的按钮或按钮。
- icon
- MessageBoxImage
指定要 MessageBoxImage 显示的图标的值。
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
示例
以下示例演示如何使用此方法重 Show 载。
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);
}
Private Sub showMessageBoxButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Configure message box
Dim message As String = "Hello, MessageBox!"
Dim caption As String = "Caption text"
Dim buttons As MessageBoxButton = MessageBoxButton.OKCancel
Dim icon As MessageBoxImage = MessageBoxImage.Information
' Show message box
Dim result As MessageBoxResult = MessageBox.Show(message, caption, buttons, icon)
End Sub
适用于
Show(Window, String, String, MessageBoxButton)
在指定窗口前面显示一个消息框。 消息框显示消息、标题栏标题和按钮;它还返回结果。
public:
static System::Windows::MessageBoxResult Show(System::Windows::Window ^ owner, System::String ^ messageBoxText, System::String ^ caption, System::Windows::MessageBoxButton button);
[System.Security.SecurityCritical]
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button);
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button);
[<System.Security.SecurityCritical>]
static member Show : System.Windows.Window * string * string * System.Windows.MessageBoxButton -> System.Windows.MessageBoxResult
static member Show : System.Windows.Window * string * string * System.Windows.MessageBoxButton -> System.Windows.MessageBoxResult
Public Shared Function Show (owner As Window, messageBoxText As String, caption As String, button As MessageBoxButton) As MessageBoxResult
参数
- button
- MessageBoxButton
一个 MessageBoxButton 值,指定要显示的按钮或按钮。
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
注解
默认情况下,消息框显示在当前处于活动状态的窗口前面。
另请参阅
适用于
Show(String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult)
显示一个消息框,其中包含消息、标题栏标题、按钮和图标;并接受默认消息框结果并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::String ^ messageBoxText, System::String ^ caption, System::Windows::MessageBoxButton button, System::Windows::MessageBoxImage icon, System::Windows::MessageBoxResult defaultResult);
[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);
public static System.Windows.MessageBoxResult Show(string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon, System.Windows.MessageBoxResult defaultResult);
[<System.Security.SecurityCritical>]
static member Show : string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage * System.Windows.MessageBoxResult -> System.Windows.MessageBoxResult
static member Show : string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage * System.Windows.MessageBoxResult -> System.Windows.MessageBoxResult
Public Shared Function Show (messageBoxText As String, caption As String, button As MessageBoxButton, icon As MessageBoxImage, defaultResult As MessageBoxResult) As MessageBoxResult
参数
- button
- MessageBoxButton
一个 MessageBoxButton 值,指定要显示的按钮或按钮。
- icon
- MessageBoxImage
指定要 MessageBoxImage 显示的图标的值。
- defaultResult
- MessageBoxResult
一个 MessageBoxResult 值,该值指定消息框的默认结果。
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
示例
以下示例演示如何使用此方法重 Show 载。
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);
}
Private Sub showMessageBoxButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Configure message box
Dim message As String = "Hello, MessageBox!"
Dim caption As String = "Caption text"
Dim buttons As MessageBoxButton = MessageBoxButton.OKCancel
Dim icon As MessageBoxImage = MessageBoxImage.Information
Dim defaultResult As MessageBoxResult = MessageBoxResult.OK
' Show message box
Dim result As MessageBoxResult = MessageBox.Show(message, caption, buttons, icon, defaultResult)
End Sub
适用于
Show(Window, String, String, MessageBoxButton, MessageBoxImage)
在指定窗口前面显示一个消息框。 消息框显示消息、标题栏标题、按钮和图标;它还返回结果。
public:
static System::Windows::MessageBoxResult Show(System::Windows::Window ^ owner, System::String ^ messageBoxText, System::String ^ caption, System::Windows::MessageBoxButton button, System::Windows::MessageBoxImage icon);
[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);
public static System.Windows.MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption, System.Windows.MessageBoxButton button, System.Windows.MessageBoxImage icon);
[<System.Security.SecurityCritical>]
static member Show : System.Windows.Window * string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage -> System.Windows.MessageBoxResult
static member Show : System.Windows.Window * string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage -> System.Windows.MessageBoxResult
Public Shared Function Show (owner As Window, messageBoxText As String, caption As String, button As MessageBoxButton, icon As MessageBoxImage) As MessageBoxResult
参数
- button
- MessageBoxButton
一个 MessageBoxButton 值,指定要显示的按钮或按钮。
- icon
- MessageBoxImage
指定要 MessageBoxImage 显示的图标的值。
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
注解
默认情况下,消息框显示在当前处于活动状态的窗口前面。
另请参阅
适用于
Show(String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult, MessageBoxOptions)
显示一个消息框,其中包含消息、标题栏标题、按钮和图标;并且接受默认消息框结果、符合指定选项并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::String ^ messageBoxText, System::String ^ caption, System::Windows::MessageBoxButton button, System::Windows::MessageBoxImage icon, System::Windows::MessageBoxResult defaultResult, System::Windows::MessageBoxOptions options);
[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);
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);
[<System.Security.SecurityCritical>]
static member Show : string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage * System.Windows.MessageBoxResult * System.Windows.MessageBoxOptions -> System.Windows.MessageBoxResult
static member Show : string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage * System.Windows.MessageBoxResult * System.Windows.MessageBoxOptions -> System.Windows.MessageBoxResult
Public Shared Function Show (messageBoxText As String, caption As String, button As MessageBoxButton, icon As MessageBoxImage, defaultResult As MessageBoxResult, options As MessageBoxOptions) As MessageBoxResult
参数
- button
- MessageBoxButton
一个 MessageBoxButton 值,指定要显示的按钮或按钮。
- icon
- MessageBoxImage
指定要 MessageBoxImage 显示的图标的值。
- defaultResult
- MessageBoxResult
一个 MessageBoxResult 值,该值指定消息框的默认结果。
- options
- MessageBoxOptions
一个 MessageBoxOptions 指定选项的值对象。
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
示例
以下示例演示如何使用此方法重 Show 载。
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);
}
Private Sub showMessageBoxButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Configure message box
Dim message As String = "Hello, MessageBox!"
Dim caption As String = "Caption text"
Dim buttons As MessageBoxButton = MessageBoxButton.OKCancel
Dim icon As MessageBoxImage = MessageBoxImage.Information
Dim defaultResult As MessageBoxResult = MessageBoxResult.OK
Dim options As MessageBoxOptions = MessageBoxOptions.RtlReading
' Show message box
Dim result As MessageBoxResult = MessageBox.Show(message, caption, buttons, icon, defaultResult, options)
End Sub
适用于
Show(Window, String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult)
在指定窗口前面显示一个消息框。 消息框显示消息、标题栏标题、按钮和图标;并接受默认消息框结果并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::Windows::Window ^ owner, System::String ^ messageBoxText, System::String ^ caption, System::Windows::MessageBoxButton button, System::Windows::MessageBoxImage icon, System::Windows::MessageBoxResult defaultResult);
[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);
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.Security.SecurityCritical>]
static member Show : System.Windows.Window * string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage * System.Windows.MessageBoxResult -> System.Windows.MessageBoxResult
static member Show : System.Windows.Window * string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage * System.Windows.MessageBoxResult -> System.Windows.MessageBoxResult
Public Shared Function Show (owner As Window, messageBoxText As String, caption As String, button As MessageBoxButton, icon As MessageBoxImage, defaultResult As MessageBoxResult) As MessageBoxResult
参数
- button
- MessageBoxButton
一个 MessageBoxButton 值,指定要显示的按钮或按钮。
- icon
- MessageBoxImage
指定要 MessageBoxImage 显示的图标的值。
- defaultResult
- MessageBoxResult
一个 MessageBoxResult 值,该值指定消息框的默认结果。
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
注解
默认情况下,消息框显示在当前处于活动状态的窗口前面。
另请参阅
适用于
Show(Window, String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult, MessageBoxOptions)
在指定窗口前面显示一个消息框。 消息框显示消息、标题栏标题、按钮和图标;并接受默认消息框结果,符合指定的选项,并返回结果。
public:
static System::Windows::MessageBoxResult Show(System::Windows::Window ^ owner, System::String ^ messageBoxText, System::String ^ caption, System::Windows::MessageBoxButton button, System::Windows::MessageBoxImage icon, System::Windows::MessageBoxResult defaultResult, System::Windows::MessageBoxOptions options);
[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);
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);
[<System.Security.SecurityCritical>]
static member Show : System.Windows.Window * string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage * System.Windows.MessageBoxResult * System.Windows.MessageBoxOptions -> System.Windows.MessageBoxResult
static member Show : System.Windows.Window * string * string * System.Windows.MessageBoxButton * System.Windows.MessageBoxImage * System.Windows.MessageBoxResult * System.Windows.MessageBoxOptions -> System.Windows.MessageBoxResult
Public Shared Function Show (owner As Window, messageBoxText As String, caption As String, button As MessageBoxButton, icon As MessageBoxImage, defaultResult As MessageBoxResult, options As MessageBoxOptions) As MessageBoxResult
参数
- button
- MessageBoxButton
一个 MessageBoxButton 值,指定要显示的按钮或按钮。
- icon
- MessageBoxImage
指定要 MessageBoxImage 显示的图标的值。
- defaultResult
- MessageBoxResult
一个 MessageBoxResult 值,该值指定消息框的默认结果。
- options
- MessageBoxOptions
一个 MessageBoxOptions 指定选项的值对象。
返回
一个 MessageBoxResult 值,该值指定用户单击了哪个消息框按钮。
- 属性
注解
默认情况下,消息框显示在当前处于活动状态的窗口前面。
另请参阅
- Activated
- Show(String, String, MessageBoxButton, MessageBoxImage, MessageBoxResult, MessageBoxOptions)