C# MessageBox

本文详细介绍了消息框MessageBox的Buttons参数与Icon参数的使用方法,包括如何展示提示信息、添加标题、询问确认操作以及使用不同类型的图标。通过21种MessageBox.Show()重载方法的总结,帮助开发者灵活运用MessageBox实现不同场景的需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • MessageBoxButtons 参数

 

成员名称 说明
  AbortRetryIgnore 消息框包含“中止”、“重试”和“忽略”按钮。
  OK 消息框包含“确定”按钮。
  OKCancel 消息框包含“确定”和“取消”按钮。
  RetryCancel 消息框包含“重试”和“取消”按钮。
  YesNo 消息框包含“是”和“否”按钮。
  YesNoCancel 消息框包含“是”、“否”和“取消”按钮。

 

  • MessageBoxIcon 参数

 

  成员名称 说明
  Asterisk 该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的。
  Error 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
  Exclamation 该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。
  Hand 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
  Information 该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的。
  None 消息框未包含符号。
  Question 该消息框包含一个符号,该符号是由一个圆圈和其中的一个问号组成的。
  Stop 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
  Warning

该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的



   MessageBox.Show()共有21中重载方法。现将其常见用法总结如下:   

 

1.MessageBox.Show("Hello~~~~");

最简单的,只显示提示信息。

 

2.MessageBox.Show("There are something wrong!","ERROR");

  可以给消息框加上标题。

 

3.if (MessageBox.Show("Delete this user?""Confirm Message",MessageBoxButtons.OKCancel) == DialogResult.OK)

{

   //delete

}

询问是否删除时会用到这个。

 

4.if (MessageBox.Show("Delete this user?""Confirm Message",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)

{

    //delete

}

可以给MessageBox加上一个Icon,.net提供常见的Icon共选择。

 

 

5.if (MessageBox.Show("Delete this user?""Confirm Message"MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2) == DialogResult.OK)

{

   //delete

}

可以改变MessageBox的默认焦点,如下:

 

6.if (MessageBox.Show("Delete this user?""Confirm Message"MessageBoxButtons.OKCancel,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2,MessageBoxOptions.RtlReading) ==DialogResult.OK)

{

   //delete

}

反向显示:

 

7.if (MessageBox.Show("Delete this user?""Confirm Message"MessageBoxButtons.OKCancel,MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign,true) ==DialogResult.OK)

{

    //delete

}

添加Help按钮:

 

8.if (MessageBox.Show("Delete this user?""Confirm Message"MessageBoxButtons.OKCancel,MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading,@"/folder/file.htm") == DialogResult.OK)

{

   //delete

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值