
Form1.cs
[csharp]
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;
}
}
}
Program.cs
static class Program
/// <summary>
/// 應用程式的主入口點。
/// </summary>
[STAThread]
static void Main()
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
partial class Form1
/// 必需的設計器變量。
private System.ComponentModel.IContainer components = null;
/// 清理所有正在使用的資源。
/// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param>
protected override void Dispose(bool disposing)
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
#region Windows 窗體設計器生成的代碼
/// 設計器支援所需的方法 - 不要
/// 使用代碼編輯器修改此方法的内容。
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;