1、 ![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img1.ph.126.net/4mpQrcTsjvBZEs5n_kiblg==/2068559603946681517.png)
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img1.ph.126.net/4mpQrcTsjvBZEs5n_kiblg==/2068559603946681517.png)
当要显示如图3个按钮时,并要获得单击不同按钮的进行不同的相应时,可以在MessageBoxButtons后面添加一个。(应该英文的点,此处为了醒目,用中文代替)可以看到提示框下方需要几个按钮的不同选择,如下图:
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img0.ph.126.net/5A0iK0aZd88XapZzXtiAAA==/1600185242700150513.png)
if (MessageBox.Show("显示提示信息", "标题", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
//单击是要进行的相应处理
}
MessageBox.Show()的返回值是 yes 、no, ok还是cancel,那需要自己在show()方法中对它可以显示的选择按钮进行设置。也就是说单击不同的按钮其返回值是不一样的。
EG:
MessageBox()在C#中使用时,通常用MessageBox的show方法来实现对话框的弹出,命名空间System.Windows.Forms
应用实例:
DialogResult r1 = MessageBox.Show("显示提示信息", "标题", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (r1.ToString()=="Yes")
{ MessageBox.Show("Yes"); }
if (r1.ToString().Equals("No"))
{ MessageBox.Show("No"); }
if (r1.ToString().Equals("Cancel"))
{ MessageBox.Show("Cancel"); }
显示效果:
单击“是”,会弹出Yes;单击“否”,会弹出No;单击“取消”,会弹出Cancel。
2、
3、![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img2.ph.126.net/-4qhs8CiXhyNE6wDQMNJtQ==/4800555727900402118.png)
MessageBox.Show("显示提示信息!", "标题");
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img2.ph.126.net/-4qhs8CiXhyNE6wDQMNJtQ==/4800555727900402118.png)
MessageBox.Show("显示提示信息!", "标题");
4、![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img1.ph.126.net/JmUiAC6x7RNRMpHuCyeE4g==/1683501835806607474.png)
if (MessageBox.Show("显示提示信息", "标题", MessageBoxButtons.OKCancel) == DialogResult.OK)
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img1.ph.126.net/JmUiAC6x7RNRMpHuCyeE4g==/1683501835806607474.png)
if (MessageBox.Show("显示提示信息", "标题", MessageBoxButtons.OKCancel) == DialogResult.OK)
{}
5、![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img0.ph.126.net/2LX6UfByQcHYeItDFiLBcA==/1402026859095959121.png)
if (MessageBox.Show("显示提示信息", "标题", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img0.ph.126.net/2LX6UfByQcHYeItDFiLBcA==/1402026859095959121.png)
{}
小注:可以给MessageBox加上一个Icon,.net提供常见的几种Icon选择。
Icon选择:![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img1.ph.126.net/3L-WFXKcRXGkKhSiISa5qQ==/3330411924540873784.png)
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img1.ph.126.net/3L-WFXKcRXGkKhSiISa5qQ==/3330411924540873784.png)
6、![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img2.ph.126.net/hQokp3gVx3xvn9Sii3-3IQ==/1758937129564960199.png)
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img2.ph.126.net/hQokp3gVx3xvn9Sii3-3IQ==/1758937129564960199.png)
if (MessageBox.Show("显示提示信息", "标题", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
{ }
小注:可以改变MessageBox的默认焦点。
7、![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img0.ph.126.net/8ijWYkWmhG3eJN8ykbaDyA==/2874985412222672907.png)
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img0.ph.126.net/8ijWYkWmhG3eJN8ykbaDyA==/2874985412222672907.png)
if (MessageBox.Show("显示提示信息","标题", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.RtlReading) == DialogResult.OK)
{}
小注:反向显示
8、![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img1.ph.126.net/zy3RcQh5g8nhSLHbq86JFA==/3406973118206173246.png)
if (MessageBox.Show("显示提示信息","标题", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign, true) == DialogResult.OK)
![MessageBox.Show Method - Complaint Free Wolrd - Complaint Free Wolrd](http://img1.ph.126.net/zy3RcQh5g8nhSLHbq86JFA==/3406973118206173246.png)
{}
9、![C MessageBox用法实例 (附效果图) - Complaint Free Wolrd - Complaint Free Wolrd](http://img0.ph.126.net/_SetvBCxxmj-qtjCY0_Mig==/4943545016069283789.png)
MessageBox.Show(" 7 个参数+帮助菜单+可用",
![C MessageBox用法实例 (附效果图) - Complaint Free Wolrd - Complaint Free Wolrd](http://img0.ph.126.net/_SetvBCxxmj-qtjCY0_Mig==/4943545016069283789.png)
"提示",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2,
MessageBoxOptions.RightAlign, // 标题向右对齐
@"d:\1.doc" //指定帮助文件的路径,点击即可打开该路径下的帮助文件。
);