winform之2---messagebox用法

 

 

MessageBox.Show();可谓是winform开发中用的次数最多的东东啦。先贴一张msdn的图解

msdn好像没有更新哎,只提供了这几种方法,并且参数名称和最新的有差别,但实际上messagebox.show()有21种重载方法,用的时候再细细查看吧。基本上都有返回结果,返回结果的如下表,一般在if判断中使用,比如DialogResult.OK这样的。

下面简单举几个例子。

复制代码
 1 1个参数。
 2 1.     1个参数。
 3 MessageBox.Show(string text);  4 // 显示具有指定文本的消息框。  5 //  6 // 参数:  7 // text:  8 // 要在消息框中显示的文本。  9 // 10 // 返回结果: 11 // System.Windows.Forms.DialogResult 值之一。
复制代码

 

复制代码
 1 2个参数。
 2 2.     2个参数。
 3 MessageBox.Show(string text, string caption);  4 // 显示具有指定文本和标题的消息框。  5 //  6 // 参数:  7 // text:  8 // 要在消息框中显示的文本。  9 // 10 // caption: 11 // 要在消息框的标题栏中显示的文本。 12 // 13 // 返回结果: 14 // System.Windows.Forms.DialogResult 值之一。
复制代码

 

复制代码
 1 3个参数
 2 3.     3个参数。
 3 MessageBox.Show(string text, string caption, MessageBoxButtons buttons);  4 // 显示具有指定文本、标题和按钮的消息框。  5 //  6 // 参数:  7 // text:  8 // 要在消息框中显示的文本。  9 // 10 // caption: 11 // 要在消息框的标题栏中显示的文本。 12 // 13 // buttons: 14 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 15 // 16 // 返回结果: 17 // System.Windows.Forms.DialogResult 值之一。 18 // 19 // 异常: 20 // System.ComponentModel.InvalidEnumArgumentException: 21 // 指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。 22 // 23 // System.InvalidOperationException: 24 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 25 // 属性指定的。
复制代码

 

 

复制代码
 1 4个参数
 2 4.     4个参数。
 3 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);  4 // 显示具有指定文本、标题、按钮和图标的消息框。  5 //  6 // 参数:  7 // text:  8 // 要在消息框中显示的文本。  9 // 10 // caption: 11 // 要在消息框的标题栏中显示的文本。 12 // 13 // buttons: 14 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 15 // 16 // icon: 17 // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 18 // 19 // 返回结果: 20 // System.Windows.Forms.DialogResult 值之一。 21 // 22 // 异常: 23 // System.ComponentModel.InvalidEnumArgumentException: 24 // 指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - 指定的 icon 25 // 参数不是 System.Windows.Forms.MessageBoxIcon 的成员。 26 // 27 // System.InvalidOperationException: 28 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 29 // 属性指定的。
复制代码

 

复制代码
 1 5个参数
 2       
 3 5. 5个参数。  4 MessageBox.Show(string text, string caption, MessageBoxButtons buttons,  5  MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);  6 // 显示具有指定文本、标题、按钮、图标和默认按钮的消息框。  7 //  8 // 参数:  9 // text: 10 // 要在消息框中显示的文本。 11 // 12 // caption: 13 // 要在消息框的标题栏中显示的文本。 14 // 15 // buttons: 16 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 17 // 18 // icon: 19 // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 20 // 21 // default Button: 22 // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 23 // 24 // 返回结果: 25 // System.Windows.Forms.DialogResult 值之一。 26 // 27 // 异常: 28 // System.ComponentModel.InvalidEnumArgumentException: 29 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon 30 // 的成员。- 或 - defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 的成员。 31 // 32 // System.InvalidOperationException: 33 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 34 // 属性指定的。
复制代码

 

 

复制代码
 1 6个参数
 2 6.     6个参数。
 3 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon,  4  MessageBoxDefaultButton defaultButton, MessageBoxOptions options);  5 // 显示具有指定文本、标题、按钮、图标、默认按钮和选项的消息框。  6 //  7 // 参数:  8 // text:  9 // 要在消息框中显示的文本。 10 // 11 // caption: 12 // 要在消息框的标题栏中显示的文本。 13 // 14 // buttons: 15 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 16 // 17 // icon: 18 // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 19 // 20 // defaultButton: 21 // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 22 // 23 // options: // 24 // System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入 25 // 0。 26 // 27 // 返回结果: 28 // System.Windows.Forms.DialogResult 值之一。 29 // 30 // 异常: 31 // System.ComponentModel.InvalidEnumArgumentException: 32 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon 33 // 的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 34 // 的成员。 35 // 36 // System.InvalidOperationException: 37 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 38 // 属性指定的。 39 // 40 // System.ArgumentException: 41 // options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和 42 // System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons 43 // 指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。
复制代码

 

 

复制代码
7个参数 
 
7.     7个参数。
                MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool displayHelpButton); // 显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和“帮助”按钮的消息框。 // // 参数: // text: // 要在消息框中显示的文本。 // // caption: // 要在消息框的标题栏中显示的文本。 // // buttons: // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 // // icon: // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 // // defaultButton: // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 // // options: // System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入 // 0。 // // helpButton: // 如果显示“帮助”按钮,则为 true;否则为 false。默认为 false。 // // 返回结果: // System.Windows.Forms.DialogResult 值之一。 // // 异常: // System.ComponentModel.InvalidEnumArgumentException: // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon // 的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton // 的成员。 // // System.InvalidOperationException: // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive // 属性指定的。 // // System.ArgumentException: // options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和 // System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons // 指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。
复制代码

 

 

复制代码
 1 也是 7 个参数
 2 8.  (也是 7 个参数)  3 MessageBox.Show(string text, string caption, MessageBoxButtons buttons,  4  MessageBoxIcon icon, MessageBoxDefaultButton defaultButton,  5 MessageBoxOptions options, string helpFilePath);  6  7 // 使用指定的帮助文件显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和“帮助”按钮的消息框。  8 //  9 // 参数: 10 // text: 11 // 要在消息框中显示的文本。 12 // 13 // caption: 14 // 要在消息框的标题栏中显示的文本。 15 // 16 // buttons: 17 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 18 // 19 // icon: 20 // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 21 // 22 // defaultButton: 23 // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 24 // 25 // options: 26 // System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入 27 // 0。 28 // 29 // helpFilePath: 30 // 用户单击“帮助”按钮时显示的“帮助”文件的路径和名称。 31 // 32 // 返回结果: 33 // System.Windows.Forms.DialogResult 值之一。 34 // 35 // 异常: 36 // System.ComponentModel.InvalidEnumArgumentException: 37 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon 38 // 的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 39 // 的成员。 40 // 41 // System.InvalidOperationException: 42 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 43 // 属性指定的。 44 // 45 // System.ArgumentException: 46 // options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和 47 // System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons 48 // 指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。
复制代码

转载于:https://www.cnblogs.com/dcdgmjzhal/p/4877685.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值