zoukankan      html  css  js  c++  java
  • 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. }  
  • 相关阅读:
    uva 532
    uva 10557
    uva 705
    uva 784
    uva 657
    uva 572
    uva 10562
    usa物价统计
    2019/6/30,道歉书
    名词收集
  • 原文地址:https://www.cnblogs.com/gc2013/p/3732615.html
Copyright © 2011-2022 走看看