C# WinForm 中 MessageBox的使用详解

 private void button1_Click(object sender, EventArgs e)
  2         {
  3             MessageBox.Show("  1  个参数 "
  4                 );
  5         }
  6

                     
  7  
  8  
  9  
 10         private void button2_Click(object sender, EventArgs e)
 11         {
 12             MessageBox.Show(" 2 个参数。。 ",
 13                                  "亮仔提示"
 14                                  );
 15         }
 16                                        
 17 

 18  
 19  
 20 
 21  
 22         private void button3_Click(object sender, EventArgs e)
 23         {
 24             MessageBox.Show(" 3 个参数。。。 ",
 25                                 " 亮仔提示",
 26                                 MessageBoxButtons.YesNoCancel
 27                                 );
 28         } 
 29                                        
 30  
 31  
 32  

 33 
 34         private void button4_Click(object sender, EventArgs e)
 35         {
 36             MessageBox.Show(" 4 个参数。。。  ",
 37                                 " 亮仔提示",
 38                                 MessageBoxButtons.OKCancel,
 39                                 MessageBoxIcon.Warning
 40                                 );
 41         }
 42                                        
 43  
 44  

 45  
 46  
 47  
 48         private void button5_Click(object sender, EventArgs e)
 49         {
 50             MessageBox.Show(" 5 个参数。。 。  ",
 51                                 " 亮仔提示",
 52                                 MessageBoxButtons.OKCancel,
 53                                 MessageBoxIcon.Warning,
 54                                 MessageBoxDefaultButton.Button2
 55                                 );
 56         }
 57                                        
 58  
 59  

 60  
 61  
 62  
 63         private void button6_Click(object sender, EventArgs e)
 64         {
 65             MessageBox.Show(" 6 个参数。。。  ",
 66                                 " 亮仔提示",
 67                                 MessageBoxButtons.OKCancel,
 68                                 MessageBoxIcon.Warning,
 69                                 MessageBoxDefaultButton.Button2,
 70                                 MessageBoxOptions.RtlReading      //ServiceNotification//.RightAlign   // 标题向右对齐。
 71                                 );
 72         }

 73                                        
 74  
 75  
 76  
 77  
 78 
 79         private void button7_Click(object sender, EventArgs e)
 80         {
 81             MessageBox.Show(" 7 个参数。。帮助菜单不可用。。。。。  ",
 82                                 " 亮仔提示",
 83                                 MessageBoxButtons.OKCancel,
 84                                 MessageBoxIcon.Warning,
 85                                 MessageBoxDefaultButton.Button2,
 86                                 MessageBoxOptions.RightAlign,
 87                                 true   // 标题向右对齐。。。。。                                );
 88         }
 89                                        
 90

 91  
 92  
 93  
 94  
 95  
 96         private void button8_Click(object sender, EventArgs e)
 97         {
 98             MessageBox.Show(" 7 个参数。帮助菜单    可用。   ",
 99                                 " 亮仔提示",
100                                 MessageBoxButtons.OKCancel,
101                                 MessageBoxIcon.Warning,
102                                 MessageBoxDefaultButton.Button2,
103                                MessageBoxOptions.RightAlign  ,   // 要使用默认风格,此处参数可设为 0    
104                                 @"C:\Documents and Settings\Administrator\桌面\新建文本文档.txt"
105                                 );
106         }
107                                        
108 
109

110 1.     1个参数。 
111  MessageBox.Show(string text); 
112 //     显示具有指定文本的消息框。 
113 // 参数:text:     要在消息框中显示的文本。 
114 // 返回结果:     System.Windows.Forms.DialogResult 值之一。
115   
116 2.     2个参数。 
117 MessageBox.Show(string text, string caption); 
118 //     显示具有指定文本和标题的消息框。 
119 // 参数: 
120 //   text:      要在消息框中显示的文本。 
121 //   caption:     要在消息框的标题栏中显示的文本。 
122 // 返回结果:      System.Windows.Forms.DialogResult 值之一。
123   
124 3.     3个参数。 
125  MessageBox.Show(string text, string caption, MessageBoxButtons buttons); 
126 //     显示具有指定文本、标题和按钮的消息框。 
127 // 参数: 
128 //   text:      要在消息框中显示的文本。 
129 //   caption:     要在消息框的标题栏中显示的文本。 
130 //   buttons:     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 
131 // 返回结果:     System.Windows.Forms.DialogResult 值之一。 
132 // 异常:     
133 //System.ComponentModel.InvalidEnumArgumentException:     指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。 
134 //   System.InvalidOperationException:     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive 属性指定的。 
135   
136 4.     4个参数。 
137 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon); 
138 //     显示具有指定文本、标题、按钮和图标的消息框。 
139 // 参数: 
140 //   text:     要在消息框中显示的文本。 
141 //   caption:     要在消息框的标题栏中显示的文本。 
142 //   buttons:     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 
143 //   icon:     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 
144 // 返回结果:     System.Windows.Forms.DialogResult 值之一。 
145 // 异常: 
146 //   System.ComponentModel.InvalidEnumArgumentException:     指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - 指定的 icon24参数不是 System.Windows.Forms.MessageBoxIcon 的成员。 
147 //   System.InvalidOperationException:     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive属性指定的。
148          
149 5.     5个参数。  
150 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton); 
151 //     显示具有指定文本、标题、按钮、图标和默认按钮的消息框。 
152 // 参数: 
153 //   text:      要在消息框中显示的文本。 
154 //   caption:     要在消息框的标题栏中显示的文本。 
155 //   buttons:     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 
156 //   icon:     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 
157 //   default Button:     System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 
158 // 返回结果:     System.Windows.Forms.DialogResult 值之一。 
159 // 异常:  
160 //   System.ComponentModel.InvalidEnumArgumentException:     buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon的成员。- 或 - defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 的成员。 
161 //   System.InvalidOperationException:     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive属性指定的。 
162   
163 6.     6个参数。 
164 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon,MessageBoxDefaultButton defaultButton, MessageBoxOptions options); 
165 //     显示具有指定文本、标题、按钮、图标、默认按钮和选项的消息框。 
166 // 参数: 
167 //   text:      要在消息框中显示的文本。 
168 //   caption:     要在消息框的标题栏中显示的文本 
169 //   buttons:    System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 
170 //   icon:     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 
171 //   defaultButton:     System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 
172 //   options:     System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入0。 
173 // 返回结果:     System.Windows.Forms.DialogResult 值之一。 
174 // 异常: 
175 //   System.ComponentModel.InvalidEnumArgumentException:     buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton的成员。 
176 //   System.InvalidOperationException:     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由System.Windows.Forms.SystemInformation.UserInteractive属性指定的。 
177 //   System.ArgumentException:     options 同时指定了System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons42指定了无效的System.Windows.Forms.MessageBoxButtons 组合。
178   
179 7.     7个参数一。 
180 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon,MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool displayHelpButton); 
181 //     显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和“帮助”按钮的消息框。 
182 // 参数: 
183 //   text:      要在消息框中显示的文本。 
184 //   caption:     要在消息框的标题栏中显示的文本。 
185 //   buttons:     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 
186 //   icon:     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 
187 //   defaultButton:     System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 
188 //   options:     System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入0。 
189 //   helpButton:     如果显示“帮助”按钮,则为 true;否则为 false。默认为 false。 
190 // 返回结果:     System.Windows.Forms.DialogResult 值之一。 
191 // 异常:34         
192 //   System.ComponentModel.InvalidEnumArgumentException:     buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton的成员。 
193 //   System.InvalidOperationException:     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由System.Windows.Forms.SystemInformation.UserInteractive属性指定的。 
194 //   System.ArgumentException:     options 同时指定了System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。 
195       
196 8.  7个参数二 
197 MessageBox.Show(string text, string caption, MessageBoxButtons buttons,MessageBoxIcon icon, MessageBoxDefaultButton defaultButton,MessageBoxOptions options, string helpFilePath); 
198 //     使用指定的帮助文件显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和“帮助”按钮的消息框。 
199 // 参数: 
200 //   text:     要在消息框中显示的文本。 
201 //   caption:     要在消息框的标题栏中显示的文本。 
202 //   buttons:     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。 
203 //   icon:     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。 
204 //   defaultButton:     System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。 
205 //   options:     System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入0。 
206 //   helpFilePath:     用户单击“帮助”按钮时显示的“帮助”文件的路径和名称。 
207 // 返回结果:     System.Windows.Forms.DialogResult 值之一。 
208 // 异常: 
209 //   System.ComponentModel.InvalidEnumArgumentException:     buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是System.Windows.Forms.MessageBoxIcon的成员。- 或 - 指定的 defaultButton 不是System.Windows.Forms.MessageBoxDefaultButton的成员。 
210 //   System.InvalidOperationException:     试图在运行模式不是用户交互模式的进程中显示System.Windows.Forms.MessageBox。这是由System.Windows.Forms.SystemInformation.UserInteractive属性指定的。 
211 //   System.ArgumentException:     options 同时指定了System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。   
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值