首页 > 学院 > 开发设计 > 正文

C#-MessageBox全部函数重载形式及举例

2019-11-17 03:09:12
字体:
来源:转载
供稿:网友
C#-MessageBox全部函数重载形式及举例

Form1.cs

[csharp]view plaincopy在CODE上查看代码片usingSystem;
  • usingSystem.Collections.Generic;
  • usingSystem.ComponentModel;
  • usingSystem.Data;
  • usingSystem.Drawing;
  • usingSystem.Linq;
  • usingSystem.Text;
  • usingSystem.Windows.Forms;
  • namespaceMessageBoxTest1
  • {
  • publicpartialclassForm1:Form
  • {
  • publicForm1()
  • {
  • InitializeComponent();
  • }
  • /*AboutMessageBox.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*/
  • PRivatevoidbutton1_Click(objectsender,EventArgse)
  • {
  • DialogResultdr=MessageBox.Show("消息信息","标题",MessageBoxButtons.YesNoCancel);
  • switch(dr)
  • {
  • caseDialogResult.Cancel:MessageBox.Show("按下了Cancel");break;
  • caseDialogResult.No:MessageBox.Show("按下了No");break;
  • caseDialogResult.Yes:MessageBox.Show("按下了Yes!");break;
  • }
  • }
  • }
  • }

    %20Program.cs

    [csharp]view%20plaincopyusingSystem;
  • usingSystem.Collections.Generic;
  • usingSystem.Linq;
  • usingSystem.Windows.Forms;
  • namespaceMessageBoxTest1
  • {
  • staticclassProgram
  • {
  • ///<summary>
  • ///应用程序的主入口点。
  • ///</summary>
  • [STAThread]
  • staticvoidMain()
  • {
  • application.EnableVisualStyles();
  • Application.SetCompatibleTextRenderingDefault(false);
  • Application.Run(newForm1());
  • }
  • }
  • }

    Form1设计

    [csharp]view%20plaincopy派生到我的代码片
      1. namespaceMessageBoxTest1
      2. {
      3. partialclassForm1
      4. {
      5. ///<summary>
      6. ///必需的设计器变量。
      7. ///</summary>
      8. privateSystem.ComponentModel.IContainercomponents=null;
      9. ///<summary>
      10. ///清理所有正在使用的资源。
      11. ///</summary>
      12. ///<paramname="disposing">如果应释放托管资源,为true;否则为false。</param>
      13. protectedoverridevoidDispose(booldisposing)
      14. {
      15. if(disposing&&(components!=null))
      16. {
      17. components.Dispose();
      18. }
      19. base.Dispose(disposing);
      20. }
      21. #regionWindows窗体设计器生成的代码
      22. ///<summary>
      23. ///设计器支持所需的方法-不要
      24. ///使用代码编辑器修改此方法的内容。
      25. ///</summary>
      26. privatevoidInitializeComponent()
      27. {
      28. this.button1=newSystem.Windows.Forms.Button();
      29. this.SuspendLayout();
      30. //
      31. //button1
      32. //
      33. this.button1.BackColor=System.Drawing.Color.Lime;
      34. this.button1.Location=newSystem.Drawing.Point(82,39);
      35. this.button1.Name="button1";
      36. this.button1.Size=newSystem.Drawing.Size(117,23);
      37. this.button1.TabIndex=1;
      38. this.button1.Text="开始测试";
      39. this.button1.UseVisualStyleBackColor=false;
      40. this.button1.Click+=newSystem.EventHandler(this.button1_Click);
      41. //
      42. //Form1
      43. //
      44. this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,12F);
      45. this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
      46. this.BackColor=System.Drawing.Color.FromArgb(((int)(((byte)(255)))),((int)(((byte)(192)))),((int)(((byte)(192)))));
      47. this.ClientSize=newSystem.Drawing.Size(296,102);
      48. this.Controls.Add(this.button1);
      49. this.Name="Form1";
      50. this.Text="MessageBoxTest";
      51. this.ResumeLayout(false);
      52. }
      53. #endregion
      54. privateSystem.Windows.Forms.Buttonbutton1;
      55. }
      56. }

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表