Form1.cs
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 MessageBoxTest1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } /*About MessageBox.Show()*/ //Show(String):消息框包含消息并返回结果 //Show(String,String) 显示消息和标题栏 //Show(Window,String) 在指定的窗口前面显示消息框,显示消息并返回结果 //Show(String,String,BoxButton) 消息,标题栏,按钮,返回结果 //Show(Window,String,String) 在指定窗口前面显示消息框,消息,标题栏 //Show(String,String,MessageBoxButton,MessageBoxImage) 消息,标题栏,按钮,图标 //Show (Window,String,String,MessageBoxButton) //Show(String,String,MessageBoxButton,MessageBoxImage) //Show(String,String,MessageBoxButton,MessageBoxImage,MessageBoxResult) //Show(Window,String,String,MessageBoxButton,MessageImage) //Show(String,String,MessageBoxButton,MessageBoxButton,MessageResult,MessageBoxOptions) 遵循指定项返回结果 //Show(Window,String,String, /*end*/ private void button1_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("消息信息", "标题", MessageBoxButtons.YesNoCancel); switch(dr) { case DialogResult.Cancel : MessageBox.Show("按下了Cancel"); break; case DialogResult.No: MessageBox.Show("按下了No"); break; case DialogResult.Yes: MessageBox.Show("按下了Yes!"); break; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace MessageBoxTest1 { static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }
namespace MessageBoxTest1 { partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.BackColor = System.Drawing.Color.Lime; this.button1.Location = new System.Drawing.Point(82, 39); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(117, 23); this.button1.TabIndex = 1; this.button1.Text = "开始测试"; this.button1.UseVisualStyleBackColor = false; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192))))); this.ClientSize = new System.Drawing.Size(296, 102); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "MessageBoxTest"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; } }