拖放一个标签,三个按钮,属性栏中设定各自的属性,最终造成的代码,就和咱们本人手动写代码是一样的。

form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace XNAGame_003
{

public partial class Form1 : Form{    public Form1()    {        InitializeComponent();    }    private void button1_Click(object sender, EventArgs e)    {        label1.ForeColor = Color.Blue;    }    private void button2_Click(object sender, EventArgs e)    {        label1.ForeColor = Color.Black;    }    private void button3_Click(object sender, EventArgs e)    {        this.Close();    }}

}

控件是拖放的,属性是属性栏中设定的。

参考一下主动的游戏代码

form1.design.cs

namespace XNAGame_003
{

partial class Form1{    ////// 必须的设计器变量。    ///private System.ComponentModel.IContainer components = null;    ////// 清理所有正在应用的资源。    //////如果应开释托管资源,为 true;否则为 www.cungun.comfalse。protected override void Dispose(bool disposing)    {        if (disposing && (components != null))        {            components.Dispose();        }        base.Dispose(disposing);    }    #region Windows 窗体设计器生成的代码    ////// 设计器反对所需的办法 - 不要    /// 应用代码编辑器批改此办法的内容。    ///private void InitializeComponent()    {        this.label1 = new System.Windows.Forms.Label();        this.button1 = new System.Windows.Forms.Button();        this.button2 = new System.Windows.Forms.Button();        this.button3 = new System.Windows.Forms.Button();        this.SuspendLayout();        //         // label1        //         this.label1.AutoSize = true;        this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));        this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;        this.label1.Location = new System.Drawing.Point(39, 34);        this.label1.Name = "label1";        this.label1.Size = new System.Drawing.Size(104, 16);        this.label1.TabIndex = 0;        this.label1.Text = "我是一个标签";        //         // button1        //         this.button1.Location = new System.Drawing.Point(42, 68);        this.button1.Name = "button1";        this.button1.Size = new System.Drawing.Size(75, 23);        this.button1.TabIndex = 1;        this.button1.Text = "蓝色";        this.button1.UseVisualStyleBackColor = true;        this.button1.Click += new System.EventHandler(this.button1_Click);        //         // button2        //         this.button2.Location = new System.Drawing.Point(42, 110);        this.button2.Name = "button2";        this.button2.Size = new System.Drawing.Size(75, 23);        this.button2.TabIndex = 2;        this.button2.Text = "彩色";        this.button2.UseVisualStyleBackColor = true;        this.button2.Click += new System.EventHandler(this.button2_Click);        //         // button3        //         this.button3.Location = new System.Drawing.Point(42, 153);        this.button3.Name = "button3";        this.button3.Size = new System.Drawing.Size(75, 23);        this.button3.TabIndex = 3;        this.button3.Text = "退出";        this.button3.UseVisualStyleBackColor = true;        this.button3.Click += new System.EventHandler(this.button3_Click);        //         // Form1        //         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;        this.ClientSize = new System.Drawing.Size(284, 262);        this.Controls.Add(this.button3);        this.Controls.Add(this.button2);        this.Controls.Add(this.button1);        this.Controls.Add(this.label1);        this.Name = "Form1";        this.Text = "Form1";        this.ResumeLayout(false);        this.PerformLayout();    }    #endregion    private System.Windows.Forms.Label label1;    private System.Windows.Forms.Button button1;    private System.Windows.Forms.Button button2;    private System.Windows.Forms.Button button3;}

}