C#: MessageBox

系统学习下Form里用到最多的MessageBox

MessageBox有21个重载的Show函数。。。都是返回DialogResult

 1     public enum DialogResult

 2     {

 3         None,

 4         OK,

 5         Cancel,

 6         Abort,

 7         Retry,

 8         Ignore,

 9         Yes,

10         No

11     }
public enum DialogResult

其中参数里带IWin32Window的函数用不太到,就不解释了

1. public static DialogResult Show(string text);

最简单的Show函数

2. public static DialogResult Show(string text, string caption);

带标题的Show函数

3. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons);

1     public enum MessageBoxButtons

2     {

3         OK,

4         OKCancel,

5         AbortRetryIgnore,

6         YesNoCancel,

7         YesNo,

8         RetryCancel

9     }
public enum MessageBoxButtons

 这里加入了MessageBoxButtons,一般是DialogResult的组合

4. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);

 1     public enum MessageBoxIcon

 2     {

 3         Asterisk = 0x40,

 4         Error = 0x10,

 5         Exclamation = 0x30,

 6         Hand = 0x10,

 7         Information = 0x40,

 8         None = 0,

 9         Quesion = 0x20,

10         Stop = 0x10,

11         Warning = 0x30

12     }
public enum MessageBoxIcon

引入了图标

5. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);

1     public enum MessageBoxDefaultButton

2     {

3         Button1 = 0,

4         Button2 = 0x100,

5         Button3 = 0x200

6     }
public enum MessageBoxDefaultButton

这里的MessageBoxDefaultButton就是在窗口出现后直接回车的Button,如果没有这个参数,就是MessageBoxDefaultButton.Button1,可以用下面这个代码测试下

DialogResult result = MessageBox.Show("hello world!!", "Say hello", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
MessageBox.Show(result.ToString());

6. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options);

1     public enum MessageBoxOptions

2     {

3         DefaultDesktopOnly = 0x20000, //显示于桌面上

4         RightAlign = 0x80000,         //放在右边

5         RtlReading = 0x100000,       //从右向左读,当然单个单词的顺序还是不变

6         ServiceNotification = 0x200000  //跟第一个一样

7     }
public enum MessageBoxOptions

这个一般用不太到了。。

7. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool displayHelpButton);

这个不常用到,因为点HelpButton啥都没有

8. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath);

Ex:

DialogResult result = MessageBox.Show("hello world!!", "Say hello", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign, @"C:\Users\Administrator\Desktop\user.txt");

9. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, string keyword);

这个函数好像不能用。。

10. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator navigator);

 1     public enum HelpNavigator

 2     {

 3         AssociateIndex = -2147483643,

 4         Find = -2147483644,

 5         Index = -2147483645,

 6         KeywordIndex = -2147483642,

 7         TableOfContents = -2147483646,

 8         Topic = -2147483647,

 9         TopicId = -2147483641

10     }
public enum HelpNavigator

不知道怎么用。。

11. public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator navigator, object param);

更不知道这个object存在的意义了。。

综上所述,平常基本只是用到了1,2,3,4

你可能感兴趣的:(message)