【函数】 <整型> MessageBox(<字符串 Text, <字符串> Title, <整型> nType,MessageBoxIcon);
【函数说明】 弹出一个消息框。
【语法】
参数:
Text <字符串>,消息框的正文;
Title <字符串>,消息框的标题;
nType <整型>,消息框的类型。
返回值:<整型>,用户在消息框上点击关闭时的选择的按钮。
【说明】
MessageBox("消息内容", "返回值 确定1",MessageBoxButtons.OK,MessageBoxIcon.Question);
MessageBox("消息内容",, "返回值 确定1 取消2",MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
MessageBox("消息内容", "返回值 终止3 重试4 忽略5",MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
MessageBox("消息内容",
MessageBox("消息内容",
MessageBox("消息内容", "返回值 重试4 取消2",MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
MessageBoxIcon: 所有图标样式
MessageBoxIcon.Question
MessageBoxIcon.Asterisk
MessageBoxIcon.Information
MessageBoxIcon.Error
MessageBoxIcon.Stop
MessageBoxIcon.Exclamation
MessageBoxIcon.Warning
MessageBoxIcon.None
MessageBox函数MessageBox()函数MessageBox是标准的windows Api函数只能在CWnd类的继承类中使用,在C#中使用时,通常用MessageBox的show方法来实现对话框的弹出,命名空间System.Windows.Forms
应用实例:
参数:
MessageBox用于显示提示信息。在.NET中,最常用的显示MessageBox的方法是MessageBox.Show 方法 (String, String, MessageBoxButtons, MessageBoxIcon),显示具有指定文本、标题、按钮和图标的消息框。
下面分别列出按钮和图标的枚举项:
- MessageBoxButtons 参数
成员名称 | 说明 | |
---|---|---|
AbortRetryIgnore | 消息框包含“中止”、“重试”和“忽略”按钮。 | |
OK | 消息框包含“确定”按钮。 | |
OKCancel | 消息框包含“确定”和“取消”按钮。 | |
RetryCancel | 消息框包含“重试”和“取消”按钮。 | |
YesNo | 消息框包含“是”和“否”按钮。 | |
YesNoCancel | 消息框包含“是”、“否”和“取消”按钮。 |
- MessageBoxIcon 参数
成员名称 | 说明 | |
---|---|---|
Asterisk | 该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的。 | |
Error | 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。 | |
Exclamation | 该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。 | |
Hand | 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。 | |
Information | 该消息框包含一个符号,该符号是由一个圆圈及其中的小写字母 i 组成的。 | |
None | 消息框未包含符号。 | |
Question | 该消息框包含一个符号,该符号是由一个圆圈和其中的一个问号组成的。 | |
Stop | 该消息框包含一个符号,该符号是由一个红色背景的圆圈及其中的白色 X 组成的。 | |
Warning | 该消息框包含一个符号,该符号是由一个黄色背景的三角形及其中的一个感叹号组成的。 |