📄 form1.cs
字号:
namespace WinApp_BgColor
{
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 button3;
private System.WinForms.Button button2;
private System.WinForms.Button button1;
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 buttonClick(object sender,EventArgs e)
{
if (sender==button1) this.BackColor=Color.Red;
else if (sender==button2) this.BackColor=Color.Blue;
else if (sender==button3) this.BackColor=Color.Green;
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container ();
this.button2 = new System.WinForms.Button ();
this.button3 = new System.WinForms.Button ();
this.button1 = new System.WinForms.Button ();
// New code added by author
EventHandler handler=new EventHandler(buttonClick);
button1.Click +=handler;
button2.Click +=handler;
button3.Click +=handler;
//@this.TrayHeight = 0;
//@this.TrayLargeIcon = false;
//@this.TrayAutoArrange = true;
button2.Visible = true;
button2.Location = new System.Drawing.Point (120, 112);
button2.Size = new System.Drawing.Size (64, 24);
button2.TabIndex = 1;
button2.Text = "蓝色";
button3.Visible = true;
button3.Location = new System.Drawing.Point (216, 176);
button3.Size = new System.Drawing.Size (64, 24);
button3.TabIndex = 2;
button3.Text = "绿色";
button1.Location = new System.Drawing.Point (24, 40);
button1.Size = new System.Drawing.Size (64, 24);
button1.TabIndex = 0;
button1.Text = "红色";
this.Text = "Form1";
this.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
this.Controls.Add (this.button3);
this.Controls.Add (this.button2);
this.Controls.Add (this.button1);
}
/// <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 + -