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 组合。

时间: 2024-08-27 15:19:26

winform之2---messagebox用法的相关文章

C#winform中OpenFileDialog的用法

private void btnOpenFileDialog_Click(object sender, EventArgs e) { OpenFileDialog oFD = new OpenFileDialog(); oFD.Title = "打开文件"; oFD.ShowHelp = true; oFD.Filter = "文本文件|*.txt|RTF文件|*.rtf|所有文件|*.*";//过滤格式 oFD.FilterIndex = 1; //格式索引 oF

C#中MessageBox用法大全(转)

我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~"); 最简单的,只显示提示信息. 2.MessageBox.Show("There are something wrong!","ERROR"); 可以给消息框加上标题. 3.if (MessageBox.Show("Delete this user?&q

winform中splitter的用法

1.将winform分为三列 整个窗体分成可以自动调节的三列的做法:1.往窗体上丢两个panel控件其中:panelLeft——设置Dock属性为“left”,并调节好其宽度panelRight——设置Dock属性为“right”,并调节好其宽度2.往窗体上丢一个splitter控件名为splitterLeft,使其与panelLeft靠紧,设置其Dock属性为“left”3.往窗体上丢一个splitter控件名为splitterRight,使其与panelRight靠紧,设置其Dock属性为“

C#中messagebox用法

[函数] <整型> MessageBox(<字符串 Text, <字符串> Title, <整型> nType,MessageBoxIcon);[函数说明] 弹出一个消息框.[语法]参数:            Text <字符串>,消息框的正文:            Title <字符串>,消息框的标题:            nType <整型>,消息框的类型.            返回值:<整型>,用户在消

C# winform 中MessageBox用法大全(附效果图) (转载+说明)

声明:这篇文章是转载的转载的,由于原作者的博客被关闭 我就不再列出了,提前先说明下,if语句中的判断有些太长,建议提前声明一个变量, DialogResult MsgBoxResult;            MsgBoxResult = MessageBox.Show("确定更新数据?", "请确定", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Butt

winform 中 MessageBox 用法大全

(转自:http://blog.csdn.net/xuenzhen123/article/details/4808005) MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show(“Hello~~~~”); 最简单的,只显示提示信息. 2.MessageBox.Show(“There are something wrong!”,“ERROR”); 可以给消息框加上标题. 3.if (MessageBox.Show(“Delete thi

Delphi中MessageBox用法

消息框是个很常用的控件,属性比较多,本文列出了它的一些常用方法,及指出了它的一些应用场合. 1.最简单用法,不带图形: MessageBox(0,'不同意','提示',MB_OK); MessageBox(0,'不同意','提示',MB_OKCANCEL ); 2.警告对话框: MessageBox(0,'密码不能为空,请务必输入密码','警告',MB_ICONEXCLAMATION); 3.提示信息对话框: MessageBox(0,'密码不能为空,请务必输入密码','提示',MB_ICONA

winform TreeView的一些用法以及异步加载

今天,主要弄了一下对于树型控件的一些方法,以及异步加载.参考: http://www.cnblogs.com/greatverve/archive/2012/03/23/winform-treeview.html 下面是TreeView的一些用法 private void BindTreeView() { treeView1.LabelEdit = false;//不可编辑 //添加结点 TreeNode root = new TreeNode(); root.Text = "根节点"

C#中MessageBox用法大全

我们在程序中经常会用到MessageBox. MessageBox.Show()共有21中重载方法.现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~"); 最简单的,只显示提示信息. 2.MessageBox.Show("There are something wrong!","ERROR"); 可以给消息框加上标题. 3.if (MessageBox.Show("Delete this user?&q

MessageBox用法

一 函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd:对话框父窗口句柄,对话框显示在Delphi窗体内,可使用窗体的Handle属性,否则可用0,使其直接作为桌面窗口的子窗口. Text:欲显示的信息字符串. Caption:对话框标题字符串. Type:对话框类型常量. 该函数的返回值为整数,用于对话框按钮的识别. 2.类型常量 对话框的类型常量可由按钮组合.缺省按钮