MessageBoxButtons 枚举

定义

指定若干常数,用以定义 MessageBox 上将显示哪些按钮

C#
public enum MessageBoxButtons
继承
MessageBoxButtons

字段

名称 说明
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

另请参阅