我有这个错误:
错误1'johny.Form1'不包含'Form1_Load'的定义 没有扩展方法'Form1_Load'接受第一个参数 类型'johny.Form1'可以找到(你错过了一个using指令 或汇编参考?)
这是来自表单设计者的代码:
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(456, 411);
this.Controls.Add(this.l6);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
错误来自这一行:
this.Load += new System.EventHandler(this.Form1_Load);
答案 0 :(得分:5)
错误告诉您Form1_Load
课程中没有Form1
方法,并且您正尝试使用该方法。
如果您在首次加载表单时不需要进行任何初始化,或者确保您拥有一个(符合EventHandler
委托的签名),请删除该行。
答案 1 :(得分:4)
这意味着Form1_Load
内的任何地方都没有Form1
方法。要解决此问题,您需要删除该事件处理程序生成的代码,或者在Form1
中添加Form1_Load
方法,例如:
this.Load += new System.EventHandler(this.Form1_Load); // <----- REMOVE THIS
OR:
public partial class Form1
{
...
Form1_Load(object sender, System.EventArgs e)
{
// Do whatever
}
}
答案 2 :(得分:1)
删除它:
this.Load += new System.EventHandler(this.Form1_Load);
或实施方法:
private void Form1_Load(object sender, System.EventArgs e)
{
//your code
}