⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 《c#技术内幕代码》
💻 CS
字号:
namespace CH7_15
{
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.WinForms;
    using System.Data;

    /// <summary>
    ///    Summary description for Form1.
    /// </summary>
    public class Form1 : System.WinForms.Form
    {
        /// <summary>
        ///    Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components;
		private System.WinForms.Button button4;
		private System.WinForms.Button button3;
		private System.WinForms.Button button2;
		private System.WinForms.Button button1;
		private System.WinForms.CheckBox checkBox4;
		private System.WinForms.CheckBox checkBox3;
		private System.WinForms.CheckBox checkBox2;
		private System.WinForms.CheckBox checkBox1;
		private System.WinForms.RadioButton radioButton4;
		private System.WinForms.RadioButton radioButton3;
		private System.WinForms.RadioButton radioButton2;
		private System.WinForms.RadioButton radioButton1;
		private System.WinForms.MenuItem menuItem6;
		private System.WinForms.MenuItem menuItem5;
		private System.WinForms.MenuItem menuItem4;
		private System.WinForms.MenuItem menuItem3;
		private System.WinForms.MenuItem menuItem2;
		private System.WinForms.MenuItem menuItem1;
		private System.WinForms.MainMenu File;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        ///    Clean up any resources being used.
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();
            components.Dispose();
        }

        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container ();
			this.button1 = new System.WinForms.Button ();
			this.button2 = new System.WinForms.Button ();
			this.button4 = new System.WinForms.Button ();
			this.menuItem2 = new System.WinForms.MenuItem ();
			this.menuItem3 = new System.WinForms.MenuItem ();
			this.radioButton3 = new System.WinForms.RadioButton ();
			this.radioButton2 = new System.WinForms.RadioButton ();
			this.radioButton1 = new System.WinForms.RadioButton ();
			this.button3 = new System.WinForms.Button ();
			this.radioButton4 = new System.WinForms.RadioButton ();
			this.checkBox4 = new System.WinForms.CheckBox ();
			this.menuItem4 = new System.WinForms.MenuItem ();
			this.checkBox2 = new System.WinForms.CheckBox ();
			this.checkBox1 = new System.WinForms.CheckBox ();
			this.checkBox3 = new System.WinForms.CheckBox ();
			this.File = new System.WinForms.MainMenu ();
			this.menuItem1 = new System.WinForms.MenuItem ();
			this.menuItem5 = new System.WinForms.MenuItem ();
			this.menuItem6 = new System.WinForms.MenuItem ();
			//@this.TrayHeight = 90;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			button1.Visible = false;
			button1.Location = new System.Drawing.Point (16, 72);
			button1.Size = new System.Drawing.Size (75, 23);
			button1.TabIndex = 8;
			button1.Text = "button1";
			button2.Visible = false;
			button2.Location = new System.Drawing.Point (152, 72);
			button2.Size = new System.Drawing.Size (75, 24);
			button2.TabIndex = 9;
			button2.Text = "button2";
			button4.Visible = false;
			button4.Location = new System.Drawing.Point (376, 72);
			button4.Size = new System.Drawing.Size (75, 23);
			button4.TabIndex = 11;
			button4.Text = "button4";
			menuItem2.Text = "E&xit";
			menuItem2.Index = 0;
			menuItem2.Click += new System.EventHandler (this.menuItem2_Click);
			menuItem3.Text = "&Show";
			menuItem3.Index = 1;
			menuItem3.MenuItems.All = new System.WinForms.MenuItem[3] {this.menuItem4, this.menuItem5, this.menuItem6};
			radioButton3.Location = new System.Drawing.Point (264, 16);
			radioButton3.Text = "radioButton3";
			radioButton3.Size = new System.Drawing.Size (100, 23);
			radioButton3.TabIndex = 2;
			radioButton3.Visible = false;
			radioButton2.Location = new System.Drawing.Point (152, 16);
			radioButton2.Text = "radioButton2";
			radioButton2.Size = new System.Drawing.Size (100, 23);
			radioButton2.TabIndex = 1;
			radioButton2.Visible = false;
			radioButton1.Location = new System.Drawing.Point (16, 16);
			radioButton1.Text = "radioButton1";
			radioButton1.Size = new System.Drawing.Size (100, 23);
			radioButton1.TabIndex = 0;
			radioButton1.Visible = false;
			button3.Visible = false;
			button3.Location = new System.Drawing.Point (256, 72);
			button3.Size = new System.Drawing.Size (75, 23);
			button3.TabIndex = 10;
			button3.Text = "button3";
			radioButton4.Location = new System.Drawing.Point (376, 16);
			radioButton4.Text = "radioButton4";
			radioButton4.Size = new System.Drawing.Size (100, 23);
			radioButton4.TabIndex = 3;
			radioButton4.Visible = false;
			checkBox4.Location = new System.Drawing.Point (376, 40);
			checkBox4.Text = "checkBox4";
			checkBox4.Size = new System.Drawing.Size (96, 32);
			checkBox4.TabIndex = 7;
			checkBox4.Visible = false;
			menuItem4.Text = "Radio Buttons";
			menuItem4.Index = 0;
			menuItem4.Click += new System.EventHandler (this.menuItem4_Click);
			checkBox2.Location = new System.Drawing.Point (152, 40);
			checkBox2.Text = "checkBox2";
			checkBox2.Size = new System.Drawing.Size (96, 32);
			checkBox2.TabIndex = 5;
			checkBox2.Visible = false;
			checkBox1.Location = new System.Drawing.Point (16, 40);
			checkBox1.Text = "checkBox1";
			checkBox1.Size = new System.Drawing.Size (96, 32);
			checkBox1.TabIndex = 4;
			checkBox1.Visible = false;
			checkBox3.Location = new System.Drawing.Point (256, 40);
			checkBox3.Text = "checkBox3";
			checkBox3.Size = new System.Drawing.Size (96, 32);
			checkBox3.TabIndex = 6;
			checkBox3.Visible = false;
			//@File.SetLocation (new System.Drawing.Point (7, 7));
			File.MenuItems.All = new System.WinForms.MenuItem[2] {this.menuItem1, this.menuItem3};
			menuItem1.Text = "&File";
			menuItem1.Index = 0;
			menuItem1.MenuItems.All = new System.WinForms.MenuItem[1] {this.menuItem2};
			menuItem5.Text = "Check Boxes";
			menuItem5.Index = 1;
			menuItem5.Click += new System.EventHandler (this.menuItem5_Click);
			menuItem6.Text = "Buttons";
			menuItem6.Index = 2;
			menuItem6.Click += new System.EventHandler (this.menuItem6_Click);
			this.Text = "Working with Menus";
			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
			this.Menu = this.File;
			this.ClientSize = new System.Drawing.Size (568, 437);
			this.Controls.Add (this.button4);
			this.Controls.Add (this.button3);
			this.Controls.Add (this.button2);
			this.Controls.Add (this.button1);
			this.Controls.Add (this.checkBox4);
			this.Controls.Add (this.checkBox3);
			this.Controls.Add (this.checkBox2);
			this.Controls.Add (this.checkBox1);
			this.Controls.Add (this.radioButton4);
			this.Controls.Add (this.radioButton3);
			this.Controls.Add (this.radioButton2);
			this.Controls.Add (this.radioButton1);
		}


		protected void menuItem6_Click (object sender, System.EventArgs e)
		{
			HideRadioButtons();
			HideCheckboxes();
			this.button1.Visible = true;
			this.button2.Visible = true;
			this.button3.Visible = true;
			this.button4.Visible = true;
		}
	
		protected void HideCheckboxes()
		{
			this.checkBox1.Visible = false;
			this.checkBox2.Visible = false;
			this.checkBox3.Visible = false;
			this.checkBox4.Visible = false;
		}

		protected void menuItem5_Click (object sender, System.EventArgs e)
		{
			HideRadioButtons();
			HideButtons();
			this.checkBox1.Visible = true;
			this.checkBox2.Visible = true;
			this.checkBox3.Visible = true;
			this.checkBox4.Visible = true;
		}
	
		protected void HideRadioButtons()
		{
            this.radioButton1.Visible = false;
            this.radioButton2.Visible = false;
            this.radioButton3.Visible = false;
            this.radioButton4.Visible = false;
		}
		protected void HideButtons()
		{
			this.button1.Visible = false;
			this.button2.Visible = false;
			this.button3.Visible = false;
			this.button4.Visible = false;
		}

		protected void menuItem4_Click (object sender, System.EventArgs e)
		{
			HideCheckboxes();
			HideButtons();
            this.radioButton1.Visible = true;
            this.radioButton2.Visible = true;
            this.radioButton3.Visible = true;
            this.radioButton4.Visible = true;
		}

		protected void menuItem2_Click (object sender, System.EventArgs e)
		{
            Close();
		}

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void Main(string[] args) 
        {
            Application.Run(new Form1());
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -