首页 > 代码库 > C#-MessageBox全部函数重载形式及举例
C#-MessageBox全部函数重载形式及举例
Form1.cs
[csharp] view plaincopy
- 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
[csharp] view plaincopy
- 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());
- }
- }
- }
Form1设计
[csharp] view plaincopy
- 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;
- }
- }
<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>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。