Form2.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:4k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. namespace SimpleWinApp
  7. {
  8. /// <summary>
  9. /// Summary description for Form2.
  10. /// </summary>
  11. public class Form2 : System.Windows.Forms.Form
  12. {
  13.     private System.Windows.Forms.Button button1;
  14.     private System.Windows.Forms.Button button2;
  15.     private System.Windows.Forms.Button button3;
  16. /// <summary>
  17. /// Required designer variable.
  18. /// </summary>
  19. private System.ComponentModel.Container components = null;
  20. public Form2()
  21. {
  22. //
  23. // Required for Windows Form Designer support
  24. //
  25. InitializeComponent();
  26. //
  27. // TODO: Add any constructor code after InitializeComponent call
  28. //
  29. }
  30. /// <summary>
  31. /// Clean up any resources being used.
  32. /// </summary>
  33. protected override void Dispose( bool disposing )
  34. {
  35. if( disposing )
  36. {
  37. if(components != null)
  38. {
  39. components.Dispose();
  40. }
  41. }
  42. base.Dispose( disposing );
  43. }
  44.     /// <summary>
  45.     /// The main entry point for the application.
  46.     /// </summary>
  47.     [STAThread]
  48.     static void Main() 
  49.     {
  50.       Application.Run(new Form2());
  51.     }
  52. #region Windows Form Designer generated code
  53. /// <summary>
  54. /// Required method for Designer support - do not modify
  55. /// the contents of this method with the code editor.
  56. /// </summary>
  57. private void InitializeComponent()
  58. {
  59.       this.button1 = new System.Windows.Forms.Button();
  60.       this.button2 = new System.Windows.Forms.Button();
  61.       this.button3 = new System.Windows.Forms.Button();
  62.       this.SuspendLayout();
  63.       // 
  64.       // button1
  65.       // 
  66.       this.button1.Location = new System.Drawing.Point(72, 48);
  67.       this.button1.Name = "button1";
  68.       this.button1.Size = new System.Drawing.Size(80, 23);
  69.       this.button1.TabIndex = 0;
  70.       this.button1.Text = "Show Form 2";
  71.       this.button1.Click += new System.EventHandler(this.button1_Click);
  72.       // 
  73.       // button2
  74.       // 
  75.       this.button2.Location = new System.Drawing.Point(72, 88);
  76.       this.button2.Name = "button2";
  77.       this.button2.Size = new System.Drawing.Size(80, 23);
  78.       this.button2.TabIndex = 1;
  79.       this.button2.Text = "Exit";
  80.       this.button2.Click += new System.EventHandler(this.button2_Click);
  81.       // 
  82.       // button3
  83.       // 
  84.       this.button3.Location = new System.Drawing.Point(72, 136);
  85.       this.button3.Name = "button3";
  86.       this.button3.Size = new System.Drawing.Size(80, 23);
  87.       this.button3.TabIndex = 2;
  88.       this.button3.Text = "Show Dialog";
  89.       this.button3.Click += new System.EventHandler(this.button3_Click);
  90.       // 
  91.       // Form2
  92.       // 
  93.       this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  94.       this.ClientSize = new System.Drawing.Size(292, 271);
  95.       this.Controls.Add(this.button3);
  96.       this.Controls.Add(this.button2);
  97.       this.Controls.Add(this.button1);
  98.       this.Name = "Form2";
  99.       this.Text = "Form2";
  100.       this.ResumeLayout(false);
  101.     }
  102. #endregion
  103.     private void button1_Click(object sender, System.EventArgs e)
  104.     {
  105.       Form1 frm = new Form1();
  106.       frm.Show();
  107.     }
  108.     private void button2_Click(object sender, System.EventArgs e)
  109.     {
  110.       Application.Exit();
  111.     }
  112.     private void button3_Click(object sender, System.EventArgs e)
  113.     {
  114.       Phone frm = new Phone();
  115.       
  116.       while(true)
  117.       {
  118.         frm.ShowDialog();
  119.         if(frm.DialogResult == DialogResult.OK)
  120.         {
  121.           MessageBox.Show("Phone number is " + frm.PhoneNumber);
  122.           if(frm.PhoneNumber.Length == 8 | frm.PhoneNumber.Length == 12)
  123.           {
  124.             break;
  125.           }
  126.           else
  127.           {
  128.             MessageBox.Show("Phone number was not formatted correctly.");
  129.           }
  130.         }
  131.         else if(frm.DialogResult == DialogResult.Cancel)
  132.         {
  133.           MessageBox.Show("Form was canceled.");
  134.           break;
  135.         }
  136.       }
  137.       frm.Close();
  138.     }
  139. }
  140. }