MesageBoxButtons 枚举

MessageBoxButtons枚举是System.Windows.Forms命名空间中的一个枚举类型,用于定义在MessageBox对话框中显示的按钮组合。它包括AbortRetryIgnore、OK、OKCancel、RetryCancel、YesNo和YesNoCancel等选项。示例代码展示了如何在用户尝试关闭窗体时使用MessageBox显示确认对话框。
摘要由CSDN通过智能技术生成

MessageBoxButtons 枚举
定义
命名空间: System.Windows.Forms
程序集: System.Windows.Forms.dll枚举
指定若干常数,用以定义 MessageBox 上将显示哪些按钮
C#

public enum MessageBoxButtons

继承
Object->ValueType->Enum->MessageBoxButtons

字段
AbortRetryIgnore 2 消息框包含“中止”、“重试”和“忽略”按钮。
OK 0 消息框包含“确定”按钮。
OKCancel 1 消息框包含“确定”和“取消”按钮。
RetryCancel 5 消息框包含“重试”和“取消”按钮。
YesNo 4 消息框包含“是”和“否”按钮。
YesNoCancel 3 消息框包含“是”、“否”和“取消”按钮。
示例
下面的代码示例演示如何使用来向 MessageBox 用户显示防止窗体关闭的机会。 此示例要求从窗体的事件中调用方法 FormClosing 。

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 类使用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值