【游戏开发】vs自动生成的代码,我就不再这里重复了。
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_002 { public partial class Form1 : Form { //私有的 Button button1; public Form1() { InitializeComponent(); this.Text = "我的第一个游戏程序"; button1 = new Button(); button1.Location = new Point(25, 25); button1.Text = "按钮一"; //button1.Click += new System.EventHandler(button1_Click); // 以前的写法,不好理解, button1.Click +=button1_Click; //现在的写法,同样有效,感觉像是借鉴了JavaScript的匿名函数 this.Controls.Add(button1); } void button1_Click(object sender, EventArgs e) { this.button1.Text = "单击了我"; } } }