WPF编程,C#中弹出式对话框 MessageBox 的几种用法。
原文:WPF编程,C#中弹出式对话框 MessageBox 的几种用法。
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)
{
//
}
询问是否删除时会用到这个。
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)
{
//
}
可以改变MessageBox的默认焦点,如下:
6、if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2,MessageBoxOptions.RtlReading) == DialogResult.OK)
{
//
}
反向显示:
7、if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign,true) == DialogResult.OK)
{
//
}
添加Help按钮:
8、if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading, @"/folder/file.htm") == DialogResult.OK)
{
//
}
指定帮助文件的路径,点击即可打开该路径下的帮助文件。
9、//HelpNavigator指定常数来指示要显示的帮助文件元素。Find 帮助文件将打开到搜索页。
if (MessageBox.Show("Delete this user?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading, @"/folder/file.htm", HelpNavigator.Find) == DialogResult.OK)
{
//delete
}
10、获取MessageBox的返回值:
首先要知道MessageBox返回的值为DialogResult类型。
返回值可能有如下:
DialogResult.OK //点击“确定”按钮后返回的值
DialogResult.YES //点击”是“按钮后返回的值
DialogResult.NO //点击”否“按钮后返回的值
例如:
DialogResult dr = MessageBox("消息内容", "返回值 是6 否7",MessageBoxButtons.YesNo, MessageBoxIcon.Hand);
if(dr == DialogResult.YES)
{
MessageBox("点击了按钮”是“");
}
else
{
MessageBox("点击了按钮”否“");
}
11、MessageBoxButtons 参数,按钮选择
成员名称 说明
AbortRetryIgnore 消息框包含“中止”、“重试”和“忽略”按钮。
OK 消息框包含“确定”按钮。
OKCancel 消息框包含“确定”和“取消”按钮。
RetryCancel 消息框包含“重试”和“取消”按钮。
YesNo 消息框包含“是”和“否”按钮。
YesNoCancel 消息框包含“是”、“否”和“取消”按钮。
12、MessageBoxIcon 参数 ,图标选择
成员名称 说明
Asterisk 该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的。
Error 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
Exclamation 该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。
Hand 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
Information 该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的。
None 消息框未包含符号。
Question 该消息框包含一个符号,该符号是由一个圆圈和其中的一个问号组成的。
Stop 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。
Warning 该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。
最新文章
- C# 使用 NPOI 库读写 Excel 文件(转载)
- gif图片加载问题
- cocos2d-x之利用富文本控件遍历xml
- 多线程-NSOperation中使用ASIHttpRequest注意事项
- 数组排序,字符串math,replace练习
- springMVC+MyBatis+Spring 整合(4) ---解决Spring MVC 对AOP不起作用的问题
- JAVA面试题——JAVA编程题1(2015.07.22——湛耀)
- 使用Keytool工具生成证书Keystore和证书签名请求文件
- java 正则表达式匹配字符串
- symfony 从request中获取当前登陆用户
- linux下如何编译python生成libpython2.5.so动态库
- 84. 从视图索引说Notes数据库(下)
- 在jsp页面下, 让eclipse完全支持HTML/JS/CSS智能提示(转)
- python中用xpath匹配文本段落内容的技巧
- python面向对象三大特性-多态
- 记录一次因代理Controller产生的404问题
- QT QListWidget 简单的操作
- php函数值传值/地址以及引用的用法
- LeetCode(37): 每k个一组翻转链表
- Date与Quartz的cron之间的相互转换