程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#-MessageBox全部函數重載形式及舉例

C#-MessageBox全部函數重載形式及舉例

編輯:C#入門知識

 

 

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. }  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved