MessageBox.Show 方法

定義

顯示訊息方塊。

多載

名稱 Description
Show(String)

顯示一個包含指定文字的訊息框。

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案與說明關鍵字。

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案, HelpNavigator以及說明主題。

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案。

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案和 HelpNavigator

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案與說明關鍵字。

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions)

在指定物件前方顯示訊息框,並包含指定的文字、說明、按鈕、圖示、預設按鈕及選項。

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案。

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, Boolean)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕。

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案和 HelpNavigator

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)

在指定物件前方顯示訊息框,並包含指定的文字、說明、按鈕、圖示及預設按鈕。

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon)

在指定物件前顯示訊息框,並包含指定的文字、說明文字、按鈕和圖示。

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示和預設按鈕。

Show(IWin32Window, String, String, MessageBoxButtons)

在指定物件前方顯示訊息框,並包含指定的文字、說明和按鈕。

Show(String, String, MessageBoxButtons, MessageBoxIcon)

顯示一個訊息框,內含指定的文字、說明文字、按鈕和圖示。

Show(IWin32Window, String, String)

在指定物件前方顯示訊息框,並附有指定的文字與說明。

Show(String, String, MessageBoxButtons)

顯示一個訊息框,內含指定的文字、說明文字和按鈕。

Show(IWin32Window, String)

在指定物件前方顯示訊息框,並顯示指定文字。

Show(String, String)

顯示包含指定文字與說明的訊息框。

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions)

顯示訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕及選項。

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object)

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案, HelpNavigator以及說明主題。

Show(String)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個包含指定文字的訊息框。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text);
public static System.Windows.Forms.DialogResult Show(string text);
public static System.Windows.Forms.DialogResult Show(string? text);
static member Show : string -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String) As DialogResult

參數

text
String

訊息框中顯示的文字。

傳回

這是其中一項 DialogResult 價值。

範例

以下程式碼範例顯示一個簡單的訊息框。

private void DisplayMessageBoxText()
{
         MessageBox.Show("Hello, world.");
}
Private Sub DisplayMessageBoxText()

    MessageBox.Show("Hello, world.")
End Sub

備註

預設訊息框會顯示 一個確定 按鈕。 訊息框標題中沒有說明文字。

適用於

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案與說明關鍵字。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::String ^ keyword);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, string keyword);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, string keyword);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, keyword As String) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

helpFilePath
String

使用者點擊說明按鈕時,該檔案的路徑與名稱。

keyword
String

使用者點擊說明按鈕時會顯示「幫助」關鍵字。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示一個子視窗的訊息框。 訊息框會顯示一個幫助按鈕。 當使用者點擊說明按鈕時, Mspaint.chm 說明檔案會被打開,並顯示出該 mspaint.chm::/paint_brush.htm 關鍵字所識別的主題。 範例要求已 Mspaint.chm 安裝說明檔案。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file, 
// and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
// associated topic.
System::Windows::Forms::DialogResult r8 = MessageBox::Show( this, "Message with Help file and keyword.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", "mspaint.chm::/paint_brush.htm" );
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file, 
// and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
// associated topic.
DialogResult r8 = MessageBox.Show (this, "Message with Help file and keyword.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 0, 
                                   "mspaint.chm", 
                                   "mspaint.chm::/paint_brush.htm");
' Display message box parented to the main form. 
' The Help button opens the Mspaint.chm Help file, 
' and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
' associated topic.
Dim r8 As DialogResult = MessageBox.Show(Me, "Message with Help file and keyword.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, 0, _
                                   "mspaint.chm", _
                                   "mspaint.chm::/paint_brush.htm")

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。 你可以用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層擁有者。

當使用者點擊說明按鈕時,參數中指定的 helpFilePath 說明檔案會被打開,並顯示由該 keyword 參數標示的說明關鍵字主題。 擁有訊息框(或主動表單)的表單也會接收該 HelpRequested 事件。

另請參閱

適用於

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案, HelpNavigator以及說明主題。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::Windows::Forms::HelpNavigator navigator, System::Object ^ param);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator, object param);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator, object? param);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * System.Windows.Forms.HelpNavigator * obj -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, navigator As HelpNavigator, param As Object) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

helpFilePath
String

使用者點擊說明按鈕時,該檔案的路徑與名稱。

navigator
HelpNavigator

這是其中一項 HelpNavigator 價值。

param
Object

使用者點擊說明按鈕時顯示的說明主題的數字 ID。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示帶有說明按鈕的訊息框。 當使用者點擊說明按鈕時, Mspaint.chm 說明檔案會被打開,並顯示出幫助索引標籤及關鍵字 ovals 所識別的主題。 範例要求已 Mspaint.chm 安裝說明檔案。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box. The Help button opens the Mspaint.chm Help file, 
// shows index with the "ovals" keyword selected, and displays the
// associated topic.
System::Windows::Forms::DialogResult r5 = MessageBox::Show( "Message with Help file and Help navigator with additional parameter.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", HelpNavigator::KeywordIndex, "ovals" );
// Display a message box. The Help button opens the Mspaint.chm Help file, 
// shows index with the "ovals" keyword selected, and displays the
// associated topic.
DialogResult r5 = MessageBox.Show ("Message with Help file and Help navigator with additional parameter.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, "mspaint.chm", 
                                   HelpNavigator.KeywordIndex, "ovals");
' Display a message box. The Help button opens the Mspaint.chm Help file, 
' shows index with the "ovals" keyword selected, and displays the
' associated topic.
Dim r5 As DialogResult = MessageBox.Show("Message with Help file and Help navigator with additional parameter.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, "mspaint.chm", _
                                   HelpNavigator.KeywordIndex, "ovals")

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

當使用者點擊說明按鈕時,參數中指定的 helpFilePath 說明檔案會被打開,並顯示該參數所 navigator 識別的說明內容。 擁有訊息框(或主動表單)的表單也會接收該 HelpRequested 事件。

彙整的說明檔案提供頁面中的目錄、索引、搜尋及關鍵字連結。 你可以使用以下數值表示navigatorTableOfContentsFindIndexTopic

你可以用來 param 進一步精煉這個 Topic 指令。 若參數中指定的 navigator 值為 TableOfContentsIndexFind,則該值應為 null。 如果 navigator 參數參考 Topic,這個值應該指向一個包含要顯示主題數值的物件。

helpFilePath參數可以是 C:\path\sample.chm 或 /folder/file.htm。

另請參閱

適用於

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

helpFilePath
String

使用者點擊說明按鈕時,該檔案的路徑與名稱。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示一個子父化為主表單的訊息框。 訊息框會顯示一個幫助按鈕。 當使用者點擊說明按鈕時, Mspaint.chm 說明檔案就會被打開。 範例要求已 Mspaint.chm 安裝說明檔案。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file.
System::Windows::Forms::DialogResult r2 = MessageBox::Show( this, "Message with Help file.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm" );
// Display a message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file.
DialogResult r2 = MessageBox.Show (this, "Message with Help file.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, 
                                   "mspaint.chm");
' Display a message box parented to the main form. 
' The Help button opens the Mspaint.chm Help file.
Dim r2 As DialogResult = MessageBox.Show(Me, "Message with Help file.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, _
                                   "mspaint.chm")

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。 你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。

當使用者點擊說明按鈕時,參數中指定的 helpFilePath 說明檔案會被打開。 擁有訊息框(或主動表單)的表單也會接收該 HelpRequested 事件。

helpFilePath參數可以是 C:\path\sample.chm 或 /folder/file.htm。

另請參閱

適用於

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案和 HelpNavigator

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::Windows::Forms::HelpNavigator navigator);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * System.Windows.Forms.HelpNavigator -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, navigator As HelpNavigator) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

helpFilePath
String

使用者點擊說明按鈕時,該檔案的路徑與名稱。

navigator
HelpNavigator

這是其中一項 HelpNavigator 價值。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示帶有說明按鈕的訊息框。 當使用者點擊說明按鈕時, Mspaint.chm 說明檔案會被打開,並顯示幫助索引標籤。 範例要求已 Mspaint.chm 安裝說明檔案。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box. The Help button opens 
// the Mspaint.chm Help file and shows the Help contents 
// on the Index tab.
System::Windows::Forms::DialogResult r3 = MessageBox::Show( "Message with Help file and Help navigator.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", HelpNavigator::Index );
// Display a message box. The Help button opens 
// the Mspaint.chm Help file and shows the Help contents 
// on the Index tab.
DialogResult r3 = MessageBox.Show ("Message with Help file and Help navigator.", 
                                   "Help Caption", MessageBoxButtons.OK,
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, "mspaint.chm", 
                                   HelpNavigator.Index);
' Display a message box. The Help button opens 
' the Mspaint.chm Help file and shows the Help contents 
' on the Index tab.
Dim r3 As DialogResult = MessageBox.Show("Message with Help file and Help navigator.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, "mspaint.chm", _
                                   HelpNavigator.Index)

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

當使用者點擊說明按鈕時,參數中指定的 helpFilePath 說明檔案會被打開,並顯示該 navigator 參數所識別的說明內容。 擁有訊息框(或主動表單)的表單也會接收該 HelpRequested 事件。

彙整說明檔案提供頁面目錄、索引、搜尋及關鍵字連結。 你可以使用以下數值表示navigatorTableOfContentsFindIndexTopic

helpFilePath參數可以是 C:\path\sample.chm 或 /folder/file.htm。

另請參閱

適用於

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案與說明關鍵字。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::String ^ keyword);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, string keyword);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, string keyword);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, keyword As String) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

helpFilePath
String

使用者點擊說明按鈕時,該檔案的路徑與名稱。

keyword
String

使用者點擊說明按鈕時會顯示「幫助」關鍵字。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示帶有說明按鈕的訊息框。 當使用者點擊說明按鈕時, Mspaint.chm 說明檔案會被打開,並顯示出該 mspaint.chm::/paint_brush.htm 關鍵字所識別的主題。 範例要求已 Mspaint.chm 安裝說明檔案。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box. The Help button opens the Mspaint.chm Help file, 
// and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
// associated topic.
System::Windows::Forms::DialogResult r7 = MessageBox::Show( "Message with Help file and keyword.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", "mspaint.chm::/paint_brush.htm" );
// Display a message box. The Help button opens the Mspaint.chm Help file, 
// and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
// associated topic.
DialogResult r7 = MessageBox.Show ("Message with Help file and keyword.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 0, 
                                   "mspaint.chm", 
                                   "mspaint.chm::/paint_brush.htm");
' Display a message box. The Help button opens the Mspaint.chm Help file, 
' and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
' associated topic.
Dim r7 As DialogResult = MessageBox.Show("Message with Help file and keyword.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, 0, _
                                   "mspaint.chm", _
                                   "mspaint.chm::/paint_brush.htm")

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

當使用者點擊說明按鈕時,參數中指定的 helpFilePath 說明檔案會被打開,並顯示由該 keyword 參數標示的說明關鍵字主題。 擁有訊息框(或主動表單)的表單也會接收該 HelpRequested 事件。

另請參閱

適用於

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

在指定物件前方顯示訊息框,並包含指定的文字、說明、按鈕、圖示、預設按鈕及選項。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

其中一個 MessageBoxDefaultButton 值指定了訊息框的預設按鈕。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

defaultButton 不屬於 MessageBoxDefaultButton

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

options 指定 DefaultDesktopOnlyServiceNotification ,並在參數中指定一個值 owner 。 這兩個選項僅在你呼叫不採用 owner 參數的版本時使用。

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示 a MessageBox 與此超載 Show支援的選項。 在確認字串變數 ServerName為空後,範例會顯示一個 MessageBox,讓使用者可以選擇取消該操作。 若 Show 方法的回傳值為 Yes,顯示 的 MessageBox 表單即為封閉。

private:
   void validateUserEntry2()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;
         
         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, MessageBoxOptions::RightAlign );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }

private void validateUserEntry2()
{

    // Checks the value of the text.

    if(serverName.Text.Length == 0)
    {

        // Initializes the variables to pass to the MessageBox.Show method.

        string message = "You did not enter a server name. Cancel this operation?";
        string caption = "No Server Name Specified";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
            MessageBoxOptions.RightAlign);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry2()


    ' Checks the value of the text.

    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.

        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)


        ' Gets the result of the MessageBox display.

        If Result = System.Windows.Forms.DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub

備註

你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。 訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

訊息框上最多只能有三個按鈕。

另請參閱

適用於

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

helpFilePath
String

使用者點擊說明按鈕時,該檔案的路徑與名稱。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示帶有說明按鈕的訊息框。 當使用者點擊說明按鈕時, Mspaint.chm 說明檔案就會被打開。 範例要求已 Mspaint.chm 安裝說明檔案。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box with a help button. 
// The Help button opens the Mspaint.chm Help file.
System::Windows::Forms::DialogResult r1 = MessageBox::Show( "Message with Help file.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm" );
// Display a message box with a help button. 
// The Help button opens the Mspaint.chm Help file.
DialogResult r1 = MessageBox.Show ("Message with Help file.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, 
                                   "mspaint.chm");
' Display a message box with a help button. 
' The Help button opens the Mspaint.chm Help file.
Dim r1 As DialogResult = MessageBox.Show("Message with Help file.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, _
                                   "mspaint.chm")

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

當使用者點擊「說明」按鈕時,參數中指定的 helpFilePath 說明檔案會被打開。 擁有訊息框(或主動表單)的表單也會接收該 HelpRequested 事件。

helpFilePath參數可以是 C:\path\sample.chm 或 /folder/file.htm。

另請參閱

適用於

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, Boolean)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, bool displayHelpButton);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, bool displayHelpButton);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, bool displayHelpButton);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * bool -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, displayHelpButton As Boolean) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

displayHelpButton
Boolean

true顯示說明按鈕;否則,。 false 預設值為 false

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示帶有說明按鈕的訊息框、處理 Control.HelpRequested 事件,以及針對事件顯示自訂說明視窗。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box with a Help button. Show a custom Help window
// by handling the HelpRequested event.
System::Windows::Forms::DialogResult AlertMessageWithCustomHelpWindow()
{
   
   // Handle the HelpRequested event for the following message.
   this->HelpRequested += gcnew System::Windows::Forms::HelpEventHandler( this, &Form1::Form1_HelpRequested );
   this->Tag = "Message with Help button.";
   
   // Show a message box with OK and Help buttons.
   System::Windows::Forms::DialogResult r = MessageBox::Show( "Message with Help button.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, true );
   
   // Remove the HelpRequested event handler to keep the event
   // from being handled for other message boxes.
   this->HelpRequested -= gcnew System::Windows::Forms::HelpEventHandler( this, &Form1::Form1_HelpRequested );
   
   // Return the dialog box result.
   return r;
}

void Form1_HelpRequested( System::Object^ sender, System::Windows::Forms::HelpEventArgs^ hlpevent )
{
   
   // Create a custom Help window in response to the HelpRequested event.
   Form^ helpForm = gcnew Form;
   
   // Set up the form position, size, and title caption.
   helpForm->StartPosition = FormStartPosition::Manual;
   helpForm->Size = System::Drawing::Size( 200, 400 );
   helpForm->DesktopLocation = Point(this->DesktopBounds.X + this->Size.Width,this->DesktopBounds.Top);
   helpForm->Text = "Help Form";
   
   // Create a label to contain the Help text.
   Label^ helpLabel = gcnew Label;
   
   // Add the label to the form and set its text.
   helpForm->Controls->Add( helpLabel );
   helpLabel->Dock = DockStyle::Fill;
   
   // Use the sender parameter to identify the context of the Help request.
   // The parameter must be cast to the Control type to get the Tag property.
   Control^ senderControl = dynamic_cast<Control^>(sender);
   helpLabel->Text = String::Format( "Help information shown in response to user action on the '{0}' message.", dynamic_cast<String^>(senderControl->Tag) );
   
   // Set the Help form to be owned by the main form. This helps
   // to ensure that the Help form is disposed of.
   this->AddOwnedForm( helpForm );
   
   // Show the custom Help window.
   helpForm->Show();
   
   // Indicate that the HelpRequested event is handled.
   hlpevent->Handled = true;
}
// Display a message box with a Help button. Show a custom Help window
// by handling the HelpRequested event.
private DialogResult AlertMessageWithCustomHelpWindow ()
{
    // Handle the HelpRequested event for the following message.
    this.HelpRequested += new System.Windows.Forms.HelpEventHandler (this.Form1_HelpRequested);

    this.Tag = "Message with Help button.";

    // Show a message box with OK and Help buttons.
    DialogResult r = MessageBox.Show ("Message with Help button.", 
                                      "Help Caption", MessageBoxButtons.OK, 
                                      MessageBoxIcon.Question, 
                                      MessageBoxDefaultButton.Button1, 
                                      0, true);

    // Remove the HelpRequested event handler to keep the event
    // from being handled for other message boxes.
    this.HelpRequested -= new System.Windows.Forms.HelpEventHandler (this.Form1_HelpRequested);

    // Return the dialog box result.
    return r;
}

private void Form1_HelpRequested (System.Object sender, System.Windows.Forms.HelpEventArgs hlpevent)
{
    // Create a custom Help window in response to the HelpRequested event.
    Form helpForm = new Form ();

    // Set up the form position, size, and title caption.
    helpForm.StartPosition = FormStartPosition.Manual;
    helpForm.Size = new Size (200, 400);
    helpForm.DesktopLocation = new Point (this.DesktopBounds.X + 
                                          this.Size.Width, 
                                          this.DesktopBounds.Top);
    helpForm.Text = "Help Form";

    // Create a label to contain the Help text.
    Label helpLabel = new Label ();

    // Add the label to the form and set its text.
    helpForm.Controls.Add (helpLabel);
    helpLabel.Dock = DockStyle.Fill;

    // Use the sender parameter to identify the context of the Help request.
    // The parameter must be cast to the Control type to get the Tag property.
    Control senderControl = sender as Control;

    helpLabel.Text = "Help information shown in response to user action on the '" + 
                      (string)senderControl.Tag + "' message.";

    // Set the Help form to be owned by the main form. This helps
    // to ensure that the Help form is disposed of.
    this.AddOwnedForm (helpForm);

    // Show the custom Help window.
    helpForm.Show ();

    // Indicate that the HelpRequested event is handled.
    hlpevent.Handled = true;
}
' Display a message box with a Help button. Show a custom Help window
' by handling the HelpRequested event.
Private Function AlertMessageWithCustomHelpWindow() As DialogResult

    ' Handle the HelpRequested event for the following message.
    AddHandler Me.HelpRequested, AddressOf Me.Form1_HelpRequested

    Me.Tag = "Message with Help button."

    ' Show a message box with OK and Help buttons.
    Dim r As DialogResult = MessageBox.Show("Message with Help button.", _
                                          "Help Caption", MessageBoxButtons.OK, _
                                          MessageBoxIcon.Question, _
                                          MessageBoxDefaultButton.Button1, _
                                          0, True)

    ' Remove the HelpRequested event handler to keep the event
    ' from being handled for other message boxes.
    RemoveHandler Me.HelpRequested, AddressOf Me.Form1_HelpRequested

    ' Return the dialog box result.
    Return r
End Function

Private Sub Form1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs)

    ' Create a custom Help window in response to the HelpRequested event.
    Dim helpForm As Form = New Form

    ' Set up the form position, size, and title caption.
    With helpForm
        .StartPosition = FormStartPosition.Manual
        .Size = New Size(200, 400)
        .DesktopLocation = New Point(Me.DesktopBounds.X + _
                                     Me.Size.Width, Me.DesktopBounds.Top)
        .Text = "Help Form"
    End With

    ' Create a label to contain the Help text.
    Dim helpLabel As Label = New Label

    ' Add the label to the form and set its text.
    helpForm.Controls.Add(helpLabel)
    helpLabel.Dock = DockStyle.Fill

    ' Use the sender parameter to identify the context of the Help request.
    ' The parameter must be cast to the Control type to get the Tag property.
    Dim senderControl As Control = CType(sender, Control)

    helpLabel.Text = "Help information shown in response to user action on the '" & _
                      CStr(senderControl.Tag) & "' message."

    ' Set the Help form to be owned by the main form. This helps
    ' to ensure that the Help form is disposed of.
    Me.AddOwnedForm(helpForm)

    ' Show the custom Help window.
    helpForm.Show()

    ' Indicate that the HelpRequested event is handled.
    hlpevent.Handled = True
End Sub

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

當使用者點擊說明按鈕時,擁有訊息框(或有效表單)的表單會接收該 HelpRequested 事件。 處理 HelpRequested 事件以執行自訂的說明操作。

另請參閱

適用於

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案和 HelpNavigator

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::Windows::Forms::HelpNavigator navigator);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * System.Windows.Forms.HelpNavigator -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, navigator As HelpNavigator) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

helpFilePath
String

使用者點擊說明按鈕時,該檔案的路徑與名稱。

navigator
HelpNavigator

這是其中一項 HelpNavigator 價值。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示一個子視窗的訊息框。 訊息框會顯示一個幫助按鈕。 當使用者點擊說明按鈕時, Mspaint.chm 說明檔案會被打開,並顯示幫助索引標籤。 範例要求已 Mspaint.chm 安裝說明檔案。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file
// and shows the Help contents on the Index tab.
System::Windows::Forms::DialogResult r4 = MessageBox::Show( this, "Message with Help file and Help navigator.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", HelpNavigator::Index );
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file
// and shows the Help contents on the Index tab.
DialogResult r4 = MessageBox.Show (this, 
                                   "Message with Help file and Help navigator.", 
                                   "Help Caption", MessageBoxButtons.OK,
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, "mspaint.chm", 
                                   HelpNavigator.Index);
' Display message box parented to the main form. 
' The Help button opens the Mspaint.chm Help file
' and shows the Help contents on the Index tab.
Dim r4 As DialogResult = MessageBox.Show(Me, _
                                      "Message with Help file and Help navigator.", _
                                      "Help Caption", MessageBoxButtons.OK, _
                                      MessageBoxIcon.Question, _
                                      MessageBoxDefaultButton.Button1, _
                                      0, "mspaint.chm", _
                                      HelpNavigator.Index)

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。 你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。

當使用者點擊說明按鈕時,參數中指定的 helpFilePath 說明檔案會被打開,並顯示該參數所 navigator 識別的說明內容。 擁有訊息框(或主動表單)的表單也會接收該 HelpRequested 事件。

彙整說明檔案提供頁面目錄、索引、搜尋及關鍵字連結。 你可以使用以下數值表示navigatorTableOfContentsFindIndexTopic

helpFilePath參數可以是 C:\path\sample.chm 或 /folder/file.htm。

另請參閱

適用於

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

在指定物件前方顯示訊息框,並包含指定的文字、說明、按鈕、圖示及預設按鈕。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

defaultButton 不屬於 MessageBoxDefaultButton

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

範例

以下程式碼範例示範如何顯示 a MessageBox 與此超載 Show支援的選項。 在確認字串變數 ServerName為空後,範例會顯示一個 MessageBox,讓使用者可以選擇取消該操作。 若 Show 方法的回傳值為 Yes,顯示 的 MessageBox 表單即為封閉。

private:
   void validateUserEntry2()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;
         
         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, MessageBoxOptions::RightAlign );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }

private void validateUserEntry2()
{

    // Checks the value of the text.

    if(serverName.Text.Length == 0)
    {

        // Initializes the variables to pass to the MessageBox.Show method.

        string message = "You did not enter a server name. Cancel this operation?";
        string caption = "No Server Name Specified";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
            MessageBoxOptions.RightAlign);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry2()


    ' Checks the value of the text.

    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.

        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)


        ' Gets the result of the MessageBox display.

        If Result = System.Windows.Forms.DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub

備註

你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。 訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

訊息框上最多只能有三個按鈕。

另請參閱

適用於

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

在指定物件前顯示訊息框,並包含指定的文字、說明文字、按鈕和圖示。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

範例

以下程式碼範例示範如何顯示 a MessageBox 與此超載 Show支援的選項。 在確認字串變數 ServerName為空後,範例會顯示一個 MessageBox,讓使用者可以選擇取消該操作。 若 Show 方法的回傳值為 Yes,顯示 的 MessageBox 表單即為封閉。

private:
   void validateUserEntry4()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;

         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons, MessageBoxIcon::Question );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }
private void validateUserEntry4()
{

    // Checks the value of the text.

    if(serverName.Text.Length == 0)
    {

        // Initializes the variables to pass to the MessageBox.Show method.

        string message = "You did not enter a server name. Cancel this operation?";
        string caption = "No Server Name Specified";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry4()

    ' Checks the value of the text.

    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.

        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        ' Gets the result of the MessageBox display.

        If Result = System.Windows.Forms.DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub

備註

你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。 訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

訊息框上最多只能有三個按鈕。

另請參閱

適用於

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示和預設按鈕。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

defaultButton 不屬於 MessageBoxDefaultButton

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

範例

以下程式碼範例示範如何顯示 a MessageBox 與此超載 Show支援的選項。 在確認字串變數 ServerName為空後,範例會顯示帶有問題框圖示的 a MessageBox ,讓使用者可以選擇取消該操作。 若 Show 方法的回傳值為 Yes,顯示 的 MessageBox 表單即為封閉。

private:
   void validateUserEntry3()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;

         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1 );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }
private void validateUserEntry3()
{

    // Checks the value of the text.

    if(serverName.Text.Length == 0)
    {

        // Initializes the variables to pass to the MessageBox.Show method.

        string message = "You did not enter a server name. Cancel this operation?";
        string caption = "No Server Name Specified";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
        MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry3()

    ' Checks the value of the text.

    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.

        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
            MessageBoxDefaultButton.Button1)

        ' Gets the result of the MessageBox display.

        If Result = System.Windows.Forms.DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If
End Sub

備註

訊息框上最多只能有三個按鈕。

另請參閱

適用於

Show(IWin32Window, String, String, MessageBoxButtons)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

在指定物件前方顯示訊息框,並包含指定的文字、說明和按鈕。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

傳回

這是其中一項 DialogResult 價值。

例外狀況

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

範例

以下程式碼範例示範如何顯示 a MessageBox 與此超載 Show支援的選項。 在確認字串變數 ServerName為空後,範例會顯示一個 MessageBox,讓使用者可以選擇取消該操作。 若 Show 方法的回傳值為 Yes,顯示 的 MessageBox 表單即為封閉。

private:
   void validateUserEntry5()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;

         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }
private void validateUserEntry5()
{

    // Checks the value of the text.

    if(serverName.Text.Length == 0)
    {

        // Initializes the variables to pass to the MessageBox.Show method.

        string message = "You did not enter a server name. Cancel this operation?";
        string caption = "No Server Name Specified";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry5()

    ' Checks the value of the text.

    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.

        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo)

        ' Gets the result of the MessageBox display.

        If Result = System.Windows.Forms.DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub

備註

你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。 訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

訊息框上最多只能有三個按鈕。

另請參閱

適用於

Show(String, String, MessageBoxButtons, MessageBoxIcon)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,內含指定的文字、說明文字、按鈕和圖示。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons所指定的參數並非 的成員MessageBoxButtons

-或-

icon所指定的參數並非 的成員MessageBoxIcon

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

範例

以下程式碼範例展示了處理Show事件時的ComboBox.DropDown其中一種方法。 要執行範例,請將以下程式碼貼入表單,並從表單的建構子或InitializeComboBox方法中呼叫該Load方法。

internal:
   // Declare ComboBox1
   System::Windows::Forms::ComboBox^ ComboBox1;

private:
   // Initialize ComboBox1.
   void InitializeComboBox()
   {
      this->ComboBox1 = gcnew ComboBox;
      this->ComboBox1->Location = System::Drawing::Point( 128, 48 );
      this->ComboBox1->Name = "ComboBox1";
      this->ComboBox1->Size = System::Drawing::Size( 100, 21 );
      this->ComboBox1->TabIndex = 0;
      this->ComboBox1->Text = "Typical";
      array<String^>^ installs = {"Typical","Compact","Custom"};
      ComboBox1->Items->AddRange( installs );
      this->Controls->Add( this->ComboBox1 );
      
      // Hook up the event handler.
      this->ComboBox1->DropDown += gcnew System::EventHandler(
         this, &Form1::ComboBox1_DropDown );
   }

   // Handles the ComboBox1 DropDown event. If the user expands the  
   // drop-down box, a message box will appear, recommending the
   // typical installation.
   void ComboBox1_DropDown( Object^ sender, System::EventArgs^ e )
   {
      MessageBox::Show( "Typical installation is strongly recommended.",
         "Install information", MessageBoxButtons::OK,
         MessageBoxIcon::Information );
   }

// Declare ComboBox1.
internal System.Windows.Forms.ComboBox ComboBox1;

// Initialize ComboBox1.
private void InitializeComboBox()
{
    this.ComboBox1 = new ComboBox();
    this.ComboBox1.Location = new System.Drawing.Point(128, 48);
    this.ComboBox1.Name = "ComboBox1";
    this.ComboBox1.Size = new System.Drawing.Size(100, 21);
    this.ComboBox1.TabIndex = 0;
    this.ComboBox1.Text	= "Typical";
    string[] installs = new string[]{"Typical", "Compact", "Custom"};
    ComboBox1.Items.AddRange(installs);
    this.Controls.Add(this.ComboBox1);
    
    // Hook up the event handler.
    this.ComboBox1.DropDown +=  
        new System.EventHandler(ComboBox1_DropDown);
}

// Handles the ComboBox1 DropDown event. If the user expands the  
// drop-down box, a message box will appear, recommending the
// typical installation.
private void ComboBox1_DropDown(object sender, System.EventArgs e)
{
    MessageBox.Show("Typical installation is strongly recommended.", 
    "Install information", MessageBoxButtons.OK, 
        MessageBoxIcon.Information);
}

' Declare ComboBox1.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

' Initialize ComboBox1.
Private Sub InitializeComboBox()
    Me.ComboBox1 = New ComboBox
    Me.ComboBox1.Location = New System.Drawing.Point(128, 48)
    Me.ComboBox1.Name = "ComboBox1"
    Me.ComboBox1.Size = New System.Drawing.Size(100, 21)
    Me.ComboBox1.TabIndex = 0
    Me.ComboBox1.Text = "Typical"
    Dim installs() As String = New String() _
        {"Typical", "Compact", "Custom"}
    ComboBox1.Items.AddRange(installs)
    Me.Controls.Add(Me.ComboBox1)
End Sub

' Handles the ComboBox1 DropDown event. If the user expands the  
' drop-down box, a message box will appear, recommending the
' typical installation.
Private Sub ComboBox1_DropDown _ 
    (ByVal sender As Object, ByVal e As System.EventArgs) _ 
    Handles ComboBox1.DropDown
    MessageBox.Show("Typical installation is strongly recommended.", _
    "Install information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

備註

訊息框上最多只能有三個按鈕。

另請參閱

適用於

Show(IWin32Window, String, String)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

在指定物件前方顯示訊息框,並附有指定的文字與說明。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption);
static member Show : System.Windows.Forms.IWin32Window * string * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

傳回

這是其中一項 DialogResult 價值。

備註

你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。 訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

預設訊息框會顯示 一個確定 按鈕。

適用於

Show(String, String, MessageBoxButtons)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,內含指定的文字、說明文字和按鈕。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons所指定的參數並非 的成員MessageBoxButtons

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

範例

以下程式碼範例示範如何顯示 a MessageBox 與此超載 Show支援的選項。 在確認字串變數 ServerName為空後,範例會顯示一個 MessageBox,讓使用者可以選擇取消該操作。 若 Show 方法的回傳值為 Yes,顯示 的 MessageBox 表單即為封閉。

private:
   void validateUserEntry()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;

         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }
private void validateUserEntry()
{
    // Checks the value of the text.
    if(serverName.Text.Length == 0)
    {
        // Initializes the variables to pass to the MessageBox.Show method.
        string message = "You did not enter a server name. Cancel this operation?";
     string caption = "Error Detected in Input";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.
        result = MessageBox.Show(message, caption, buttons);
        if (result == System.Windows.Forms.DialogResult.Yes)
        {
            // Closes the parent form.
            this.Close();
        }
    }
}
Private Sub ValidateUserEntry()
    ' Checks the value of the text.
    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.
        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "Error Detected in Input"
        Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays the MessageBox
        Result = MessageBox.Show(Message, Caption, Buttons)

        ' Gets the result of the MessageBox display.
        If Result = System.Windows.Forms.DialogResult.Yes Then
            ' Closes the parent form.
            Me.Close()
        End If
    End If
End Sub

備註

訊息框上最多只能有三個按鈕。

另請參閱

適用於

Show(IWin32Window, String)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

在指定物件前方顯示訊息框,並顯示指定文字。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text);
static member Show : System.Windows.Forms.IWin32Window * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

傳回

這是其中一項 DialogResult 價值。

備註

你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。 訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。

預設訊息框會顯示 一個確定 按鈕。 訊息框標題中沒有說明文字。

適用於

Show(String, String)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示包含指定文字與說明的訊息框。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption);
public static System.Windows.Forms.DialogResult Show(string text, string caption);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption);
static member Show : string * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

傳回

這是其中一項 DialogResult 價值。

備註

預設訊息框會顯示 一個確定 按鈕。

適用於

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕及選項。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options);
public static System.Windows.Forms.DialogResult Show(string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options);
public static System.Windows.Forms.DialogResult Show(string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions) As DialogResult

參數

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示 a MessageBox 與此超載 Show支援的選項。 在確認字串變數 ServerName為空後,範例會顯示帶有問題框圖示的 a MessageBox ,讓使用者可以選擇取消該操作。 範例中使用 RightAlign 列舉的成員 MessageBoxOptions 將文字對齊到對話框的右側邊緣。 若 Show 方法的回傳值為 Yes,顯示 的 MessageBox 表單即為封閉。

private:
   void validateUserEntry2()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;
         
         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, MessageBoxOptions::RightAlign );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }

private void validateUserEntry2()
{

    // Checks the value of the text.

    if(serverName.Text.Length == 0)
    {

        // Initializes the variables to pass to the MessageBox.Show method.

        string message = "You did not enter a server name. Cancel this operation?";
        string caption = "No Server Name Specified";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
            MessageBoxOptions.RightAlign);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry2()


    ' Checks the value of the text.

    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.

        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)


        ' Gets the result of the MessageBox display.

        If Result = System.Windows.Forms.DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub

備註

訊息框上最多只能有三個按鈕。

另請參閱

適用於

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object)

來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs
來源:
MessageBox.cs

顯示一個訊息框,包含指定的文字、說明文字、按鈕、圖示、預設按鈕、選項及說明按鈕,使用指定的說明檔案, HelpNavigator以及說明主題。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::Windows::Forms::HelpNavigator navigator, System::Object ^ param);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator, object param);
public static System.Windows.Forms.DialogResult Show(System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator, object? param);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * System.Windows.Forms.HelpNavigator * obj -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, navigator As HelpNavigator, param As Object) As DialogResult

參數

owner
IWin32Window

這個實作 IWin32Window 會擁有模態對話框。

text
String

訊息框中顯示的文字。

caption
String

文字要顯示在訊息框的標題欄。

buttons
MessageBoxButtons

其中一個 MessageBoxButtons 數值是指定訊息框中要顯示哪些按鈕的。

icon
MessageBoxIcon

其中一個 MessageBoxIcon 值是指定訊息框中要顯示哪個圖示的。

defaultButton
MessageBoxDefaultButton

MessageBoxDefaultButton其中一個值是指定訊息框預設按鈕的。

options
MessageBoxOptions

其中一個 MessageBoxOptions 值是指定訊息框將使用哪些顯示與關聯選項的。 如果你想用預設值,可以直接通過 0。

helpFilePath
String

使用者點擊說明按鈕時,該檔案的路徑與名稱。

navigator
HelpNavigator

這是其中一項 HelpNavigator 價值。

param
Object

使用者點擊說明按鈕時顯示的說明主題的數字 ID。

傳回

這是其中一項 DialogResult 價值。

例外狀況

buttons 不屬於 MessageBoxButtons

-或-

icon 不屬於 MessageBoxIcon

-或-

指定的 defaultButton 不是 的 MessageBoxDefaultButton成員。

嘗試在未以使用者互動模式運行的程序中顯示 。MessageBox 這由 UserInteractive 屬性所規定。

options 同時指定 DefaultDesktopOnlyServiceNotification

-或-

buttons指定了一個無效的組合。MessageBoxButtons

範例

以下程式碼範例示範如何顯示一個子視窗的訊息框。 訊息框會顯示一個幫助按鈕。 當使用者點擊說明按鈕時, Mspaint.chm 說明檔案會被打開,並顯示出幫助索引標籤及關鍵字 ovals 所識別的主題。 範例要求已 Mspaint.chm 安裝說明檔案。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file, 
// shows index with the "ovals" keyword selected, and displays the
// associated topic.
System::Windows::Forms::DialogResult r6 = MessageBox::Show( this, "Message with Help file and Help navigator with additional parameter.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", HelpNavigator::KeywordIndex, "ovals" );
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file, 
// shows index with the "ovals" keyword selected, and displays the
// associated topic.
DialogResult r6 = MessageBox.Show (this, 
                                   "Message with Help file and Help navigator with additional parameter.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, "mspaint.chm", 
                                   HelpNavigator.KeywordIndex, "ovals");
' Display message box parented to the main form. 
' The Help button opens the Mspaint.chm Help file, 
' shows index with the "ovals" keyword selected, and displays the
' associated topic.
Dim r6 As DialogResult = MessageBox.Show(Me, _
                                   "Message with Help file and Help navigator with additional parameter.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, "mspaint.chm", _
                                   HelpNavigator.KeywordIndex, "ovals")

備註

訊息框是一種模態對話框,意即除了模態表單上的物件外,任何輸入(鍵盤或滑鼠點擊)都不會發生。 程式必須在輸入另一個模態前,先隱藏或關閉模態表單(通常是回應使用者操作)。 你可以使用這個 owner 參數指定一個特定物件,該物件實 IWin32Window 作了介面,該物件將作為對話框的頂層視窗和擁有者。

當使用者點擊說明按鈕時,參數中指定的 helpFilePath 說明檔案會被打開,並顯示該參數所 navigator 識別的說明內容。 擁有訊息框(或主動表單)的表單也會接收該 HelpRequested 事件。

彙整的說明檔案提供頁面中的目錄、索引、搜尋及關鍵字連結。 你可以使用以下數值表示navigatorTableOfContentsFindIndexTopic

你可以用來 param 進一步精煉這個 Topic 指令。 若參數中指定的 navigator 值為 TableOfContentsIndexFind,則該值應為 null。 如果 navigator 參數參考 Topic,這個值應該指向一個包含要顯示主題數值的物件。

helpFilePath參數可以是 C:\path\sample.chm 或 /folder/file.htm。

另請參閱

適用於