namespace test { using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; public class Form1 : Form // public partial class Form1 : Form { private Button button1; //(移动到Form1.Designer.cs中) private IContainer components; //删除 替换 private System.ComponentModel.IContainer components = null; //(移动到Form1.Designer.cs中) private Label label1; //(移动到Form1.Designer.cs中) public Form1() { this.InitializeComponent(); //去掉this. } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("这是测试程序!"); } protected override void Dispose(bool disposing) { if (disposing && (this.components != null)) { this.components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() //(移动到Form1.Designer.cs中) { this.button1 = new Button(); this.label1 = new Label(); base.SuspendLayout(); //InitializeComponent函数里面的所有base替换为this this.button1.Location = new Point(0x62, 0xaf); this.button1.Name = "button1"; this.button1.Size = new Size(0x4b, 0x17); this.button1.TabIndex = 0; this.button1.Text = "按钮1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new EventHandler(this.button1_Click); this.label1.AutoSize = true; this.label1.Location = new Point(0x75, 0x68); this.label1.Name = "label1"; this.label1.Size = new Size(0x23, 12); this.label1.TabIndex = 1; this.label1.Text = "标签1"; base.AutoScaleDimensions = new SizeF(6f, 12f); //base替换为this base.AutoScaleMode = AutoScaleMode.Font; base.ClientSize = new Size(0x11c, 0x105); base.Controls.Add(this.label1); base.Controls.Add(this.button1); base.Name = "Form1"; this.Text = "Form1"; base.ResumeLayout(false); base.PerformLayout(); } } }