首页 > 代码库 > C#-MessageBox全部函数重载形式及举例

C#-MessageBox全部函数重载形式及举例

 

 

Form1.cs 

 

[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9.   
  10. namespace MessageBoxTest1  
  11. {  
  12.     public partial class Form1 : Form  
  13.     {  
  14.         public Form1()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.         /*About MessageBox.Show()*/  
  19.         //Show(String):消息框包含消息并返回结果  
  20.         //Show(String,String) 显示消息和标题栏  
  21.         //Show(Window,String) 在指定的窗口前面显示消息框,显示消息并返回结果  
  22.         //Show(String,String,BoxButton)  消息,标题栏,按钮,返回结果  
  23.         //Show(Window,String,String) 在指定窗口前面显示消息框,消息,标题栏  
  24.         //Show(String,String,MessageBoxButton,MessageBoxImage) 消息,标题栏,按钮,图标  
  25.         //Show (Window,String,String,MessageBoxButton)   
  26.         //Show(String,String,MessageBoxButton,MessageBoxImage)  
  27.         //Show(String,String,MessageBoxButton,MessageBoxImage,MessageBoxResult)  
  28.         //Show(Window,String,String,MessageBoxButton,MessageImage)  
  29.         //Show(String,String,MessageBoxButton,MessageBoxButton,MessageResult,MessageBoxOptions)  遵循指定项返回结果  
  30.         //Show(Window,String,String,  
  31.         /*end*/  
  32.         private void button1_Click(object sender, EventArgs e)  
  33.         {  
  34.             DialogResult dr = MessageBox.Show("消息信息""标题", MessageBoxButtons.YesNoCancel);  
  35.             switch(dr)  
  36.             {  
  37.                 case DialogResult.Cancel : MessageBox.Show("按下了Cancel"); break;  
  38.                 case DialogResult.No: MessageBox.Show("按下了No"); break;  
  39.                 case DialogResult.Yes: MessageBox.Show("按下了Yes!"); break;  
  40.             }  
  41.         }  
  42.     }  
  43. }  


Program.cs

 

 

[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Windows.Forms;  
  5.   
  6. namespace MessageBoxTest1  
  7. {  
  8.     static class Program  
  9.     {  
  10.         /// <summary>  
  11.         /// 应用程序的主入口点。  
  12.         /// </summary>  
  13.         [STAThread]  
  14.         static void Main()  
  15.         {  
  16.             Application.EnableVisualStyles();  
  17.             Application.SetCompatibleTextRenderingDefault(false);  
  18.             Application.Run(new Form1());  
  19.         }  
  20.     }  
  21. }  


Form1设计

[csharp] view plaincopy在CODE上查看代码片派生到我的代码片
 
    1. namespace MessageBoxTest1  
    2. {  
    3.     partial class Form1  
    4.     {  
    5.         /// <summary>  
    6.         /// 必需的设计器变量。  
    7.         /// </summary>  
    8.         private System.ComponentModel.IContainer components = null;  
    9.   
    10.         /// <summary>  
    11.         /// 清理所有正在使用的资源。  
    12.         /// </summary>  
    13.         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>  
    14.         protected override void Dispose(bool disposing)  
    15.         {  
    16.             if (disposing && (components != null))  
    17.             {  
    18.                 components.Dispose();  
    19.             }  
    20.             base.Dispose(disposing);  
    21.         }  
    22.  
    23.         #region Windows 窗体设计器生成的代码  
    24.   
    25.         /// <summary>  
    26.         /// 设计器支持所需的方法 - 不要  
    27.         /// 使用代码编辑器修改此方法的内容。  
    28.         /// </summary>  
    29.         private void InitializeComponent()  
    30.         {  
    31.             this.button1 = new System.Windows.Forms.Button();  
    32.             this.SuspendLayout();  
    33.             //   
    34.             // button1  
    35.             //   
    36.             this.button1.BackColor = System.Drawing.Color.Lime;  
    37.             this.button1.Location = new System.Drawing.Point(82, 39);  
    38.             this.button1.Name = "button1";  
    39.             this.button1.Size = new System.Drawing.Size(117, 23);  
    40.             this.button1.TabIndex = 1;  
    41.             this.button1.Text = "开始测试";  
    42.             this.button1.UseVisualStyleBackColor = false;  
    43.             this.button1.Click += new System.EventHandler(this.button1_Click);  
    44.             //   
    45.             // Form1  
    46.             //   
    47.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);  
    48.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;  
    49.             this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));  
    50.             this.ClientSize = new System.Drawing.Size(296, 102);  
    51.             this.Controls.Add(this.button1);  
    52.             this.Name = "Form1";  
    53.             this.Text = "MessageBoxTest";  
    54.             this.ResumeLayout(false);  
    55.   
    56.         }  
    57.  
    58.         #endregion  
    59.   
    60.         private System.Windows.Forms.Button button1;  
    61.   
    62.     }  
    63. }  
<iframe id="google_ads_frame2" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1400309160&flash=0&url=http%3A%2F%2Fwww.cnblogs.com%2Fgc2013%2Fp%2F3732615.html&dt=1400309163075&shv=r20140513&cbv=r20140417&saldr=sb&correlator=1400309162190&frm=20&ga_vid=227879072.1400240514&ga_sid=1400302831&ga_hid=483161147&ga_fc=1&u_tz=480&u_his=113&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=verdana&dfs=12&adx=0&ady=66364&biw=314&bih=74&eid=317150304&oid=3&rx=0&eae=0&docm=9&vis=0&fu=0&ifi=2&xpc=Q0fR35vLku&p=http%3A//www.cnblogs.com&dtd=53" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame2" marginWidth="0" scrolling="no" hspace="0"></iframe><iframe id="google_ads_frame3" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1400309160&flash=0&url=http%3A%2F%2Fwww.cnblogs.com%2Fgc2013%2Fp%2F3732615.html&dt=1400309163135&shv=r20140513&cbv=r20140417&saldr=sb&prev_slotnames=8660799060&correlator=1400309162190&frm=20&ga_vid=227879072.1400240514&ga_sid=1400302831&ga_hid=483161147&ga_fc=1&u_tz=480&u_his=113&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=verdana&dfs=12&adx=304&ady=66614&biw=314&bih=74&eid=317150304&oid=3&rx=0&eae=0&docm=9&vis=0&fu=0&ifi=3&xpc=1J8NJyObdQ&p=http%3A//www.cnblogs.com&dtd=42" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame3" marginWidth="0" scrolling="no" hspace="0"></iframe>