MessageBox()的参数用法总结

1、MessageBox.Show("hello","world!",MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
我想在按了 “是”之后 做一些工作,怎么知道我按的是 “是 ”还是“取消”怎么写代码?
if (MessageBox.Show("hello", "world!", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK) { //你要做的事情 } else { }//取消同理 DialogResult.Cancel

2、C#中MessageBox.Show("","",MessageBoxButtons.OK);怎样让消息框中的确定按钮(MessageBoxButtons.OK)居中

在消息框的括号内中给参数也可以,要详细,回答正确者,我给高分!请各位大师解答!!!!!   

我是说消息框中的设的确定按钮(MessageBoxButtons.OK)居中 

,不是消息框,听清楚没有?


MessageBox的位置没方法控制,它会自动在屏幕中间显示,
你可以设置主窗体的位置屏幕居中:this.StartPosition = FormStartPosition.CenterScreen;
当然,你也可以自己定义个对话框窗体。
MessageBox.Show("要显示的文本内容","标题中的文本",MessageBoxButtons.OK,MessageBoxIcon.Information);//后面两个参数分别是 按钮类型和图标类型。
3、 http://www.cnblogs.com/music-liang/archive/2011/09/14/2176021.html


下面是详细的代码  。

 

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        {
            MessageBox.Show("  1  个参数 "
                );
        }
        {
            MessageBox.Show(" 2 个参数。。 ",
                                 "亮仔提示"
                                 );
        }
 
 
        {
            MessageBox.Show(" 3 个参数。。。 ",
                                " 亮仔提示",
                                MessageBoxButtons.YesNoCancel
                                );
        } 
        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 4 个参数。。。  ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning
                                );
        }
        {
            MessageBox.Show(" 5 个参数。。 。  ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2,
                                );
        }
        {
            MessageBox.Show(" 6 个参数。。。  ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2,
                                MessageBoxOptions.RtlReading      //ServiceNotification//.RightAlign   // 标题向右对齐。
                                );
        private void button7_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 7 个参数。。帮助菜单不可用。。。。。  ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2,
                                MessageBoxOptions.RightAlign,
                                true   // 标题向右对齐。。。。。
                            );
 
        {
            MessageBox.Show(" 7 个参数。帮助菜单    可用。   ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2,
                               MessageBoxOptions.RightAlign  ,   // 要使用默认风格,此处参数可设为 0    
                                @"C:\Documents and Settings\Administrator\桌面\新建文本文档.txt"
     
                                );
        }
    }
}

                                      

 

                                      


                                      


                                      

 

                                      

 

                                      

 

                                      


                                      



  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值