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

📄 form1.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
namespace WindowsAppl_button
{
    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 Green;
		private System.WinForms.Button Blue;
		private System.WinForms.Button Red;

        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.Green = new System.WinForms.Button ();
			this.Blue = new System.WinForms.Button ();
			this.Red = new System.WinForms.Button ();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			EventHandler handler=new EventHandler(ButtonClick);
			// Green.Visible = false;
			Green.Location = new System.Drawing.Point (168, 152);
			Green.Size = new System.Drawing.Size (64, 32);
			Green.TabIndex = 2;
			Green.Text = "Green";
            Green.Click+=handler;
            Controls.Add(Green);

            // 
			// Blue.Visible = false;
			Blue.Location = new System.Drawing.Point (104, 88);
			Blue.Size = new System.Drawing.Size (64, 32);
			Blue.TabIndex = 1;
			Blue.Text = "Blue";
			Blue.Click+=handler;
            Controls.Add(Blue);

            // 

			Red.Location = new System.Drawing.Point (56, 24);
			Red.Size = new System.Drawing.Size (64, 32);
			Red.TabIndex = 0;
			Red.Text = "Red";
			Red.Click+=handler;
            Controls.Add(Red);

            // 
			this.Text = "Form1";
			this.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
			this.Controls.Add (this.Green);
			this.Controls.Add (this.Blue);
			this.Controls.Add (this.Red);
		}
        private void ButtonClick(object sender,EventArgs e)
		{
		 if (sender==Red) this.BackColor=Color.Red;
						 else if (sender==Blue) this.BackColor=Color.Blue;
						 else this.BackColor=Color.Green;				 			 
		}
        
        /// <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 + -