閱讀英文

共用方式為


MessageBoxButtons 列舉

定義

指定定義那個按鈕要顯示在 MessageBox 上的常數。

C#
public enum MessageBoxButtons
繼承
MessageBoxButtons

欄位

名稱 Description
AbortRetryIgnore 2

訊息方塊包含 [中止]、[重試] 和 [忽略] 按鈕。

CancelTryContinue 6

指定訊息方塊包含 [取消]、[重試] 和 [繼續] 按鈕。

OK 0

訊息方塊包含 [確定] 按鈕。

OKCancel 1

訊息方塊包含 [確定] 和 [取消] 按鈕。

RetryCancel 5

訊息方塊包含 [重試] 和 [取消] 按鈕。

YesNo 4

訊息方塊包含 [是] 和 [否] 按鈕。

YesNoCancel 3

訊息方塊包含 [是]、[否] 和 [取消] 按鈕。

範例

下列程式碼範例示範如何使用 MessageBox ,讓使用者有機會防止表單關閉。 此範例需要從 FormClosing 表單的 事件呼叫 方法。

C#
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    const string message =
        "Are you sure that you would like to close the form?";
    const string caption = "Form Closing";
    var result = MessageBox.Show(message, caption,
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question);

    // If the no button was pressed ...
    if (result == DialogResult.No)
    {
        // cancel the closure of the form.
        e.Cancel = true;
    }
}

備註

這項列舉供 MessageBox 類別使用。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱