声明:IWin32Window owner , HelpNavigator navigator , string keyword
上面的三个参数类型不是很了解。没有做讨论。
等以后了解多了,再做补充。。。
下面讨论的一些常用参数,在平时使用,已经绰绰有余了。。。
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
下面是详细的代码 。
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;
namespace 对话框_终极版 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) { MessageBox.Show(" 1 个参数 " ); }
private void button2_Click(object sender, EventArgs e) { MessageBox.Show(" 2 个参数。。 ", "亮仔提示" ); }
private void button3_Click(object sender, EventArgs e) { MessageBox.Show(" 3 个参数。。。 ", " 亮仔提示", MessageBoxButtons.YesNoCancel ); }
private void button4_Click(object sender, EventArgs e) { MessageBox.Show(" 4 个参数。。。 ", " 亮仔提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning ); }
private void button5_Click(object sender, EventArgs e) { MessageBox.Show(" 5 个参数。。 。 ", " 亮仔提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2 ); }
private void button6_Click(object sender, EventArgs e) { 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 // 标题向右对齐。。。。。 );
}
private void button8_Click(object sender, EventArgs e) { MessageBox.Show(" 7 个参数。帮助菜单 可用。 ", " 亮仔提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign , // 要使用默认风格,此处参数可设为 0 @"C:\Documents and Settings\Administrator\桌面\新建文本文档.txt" ); }
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
下面是一些解释。。下面是一些解释。。
下面是一些解释。。下面是一些解释。。
1 1. 1个参数。 2 MessageBox.Show(string text); 3 // 显示具有指定文本的消息框。 4 // 5 // 参数: 6 // text: 7 // 要在消息框中显示的文本。 8 // 9 // 返回结果: 10 // System.Windows.Forms.DialogResult 值之一。
1 2. 2个参数。 2 MessageBox.Show(string text, string caption); 3 // 显示具有指定文本和标题的消息框。 4 // 5 // 参数: 6 // text: 7 // 要在消息框中显示的文本。 8 // 9 // caption: 10 // 要在消息框的标题栏中显示的文本。 11 // 12 // 返回结果: 13 // System.Windows.Forms.DialogResult 值之一。
1 3. 3个参数。 2 MessageBox.Show(string text, string caption, MessageBoxButtons buttons); 3 // 显示具有指定文本、标题和按钮的消息框。 4 // 5 // 参数: 6 // text: 7 // 要在消息框中显示的文本。 8 // 9 // caption: 10 // 要在消息框的标题栏中显示的文本。 11 // 12 // buttons: 13 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 14 // 15 // 返回结果: 16 // System.Windows.Forms.DialogResult 值之一。 17 // 18 // 异常: 19 // System.ComponentModel.InvalidEnumArgumentException: 20 // 指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。 21 // 22 // System.InvalidOperationException: 23 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 24 // 属性指定的。
1 4. 4个参数。 2 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon); 3 // 显示具有指定文本、标题、按钮和图标的消息框。 4 // 5 // 参数: 6 // text: 7 // 要在消息框中显示的文本。 8 // 9 // caption: 10 // 要在消息框的标题栏中显示的文本。 11 // 12 // buttons: 13 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 14 // 15 // icon: 16 // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 17 // 18 // 返回结果: 19 // System.Windows.Forms.DialogResult 值之一。 20 // 21 // 异常: 22 // System.ComponentModel.InvalidEnumArgumentException: 23 // 指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - 指定的 icon 24 // 参数不是 System.Windows.Forms.MessageBoxIcon 的成员。 25 // 26 // System.InvalidOperationException: 27 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 28 // 属性指定的。
1 2 5. 5个参数。 3 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, 4 MessageBoxIcon icon, MessageBoxDefaultButton defaultButton); 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 // default Button: 21 // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 22 // 23 // 返回结果: 24 // System.Windows.Forms.DialogResult 值之一。 25 // 26 // 异常: 27 // System.ComponentModel.InvalidEnumArgumentException: 28 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon 29 // 的成员。- 或 - defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 的成员。 30 // 31 // System.InvalidOperationException: 32 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 33 // 属性指定的。
1 6. 6个参数。 2 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, 3 MessageBoxDefaultButton defaultButton, MessageBoxOptions options); 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 // defaultButton: 20 // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 21 // 22 // options: // 23 // System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入 24 // 0。 25 // 26 // 返回结果: 27 // System.Windows.Forms.DialogResult 值之一。 28 // 29 // 异常: 30 // System.ComponentModel.InvalidEnumArgumentException: 31 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon 32 // 的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 33 // 的成员。 34 // 35 // System.InvalidOperationException: 36 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 37 // 属性指定的。 38 // 39 // System.ArgumentException: 40 // options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和 41 // System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons 42 // 指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。
1 2 7. 7个参数。 3 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, 4 MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool displayHelpButton); 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 // helpButton: 28 // 如果显示“帮助”按钮,则为 true;否则为 false。默认为 false。 29 // 30 // 返回结果: 31 // System.Windows.Forms.DialogResult 值之一。 32 // 33 // 异常: 34 // System.ComponentModel.InvalidEnumArgumentException: 35 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon 36 // 的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 37 // 的成员。 38 // 39 // System.InvalidOperationException: 40 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 41 // 属性指定的。 42 // 43 // System.ArgumentException: 44 // options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和 45 // System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons 46 // 指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。 47 48 49 50
1 8. (也是 7 个参数) 2 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, 3 MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, 4 MessageBoxOptions options, string helpFilePath); 5 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 // defaultButton: 22 // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 23 // 24 // options: 25 // System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入 26 // 0。 27 // 28 // helpFilePath: 29 // 用户单击“帮助”按钮时显示的“帮助”文件的路径和名称。 30 // 31 // 返回结果: 32 // System.Windows.Forms.DialogResult 值之一。 33 // 34 // 异常: 35 // System.ComponentModel.InvalidEnumArgumentException: 36 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon 37 // 的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 38 // 的成员。 39 // 40 // System.InvalidOperationException: 41 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 42 // 属性指定的。 43 // 44 // System.ArgumentException: 45 // options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和 46 // System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons 47 // 指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。 48
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|