'johny.Form1' does not contain a definition for 'Form1_Load'

大憨熊 提交于 2019-12-10 23:28:00

问题


I have this error:

Error 1 'johny.Form1' does not contain a definition for 'Form1_Load' and no extension method 'Form1_Load' accepting a first argument of type 'johny.Form1' could be found (are you missing a using directive or an assembly reference?)

This is my code from the form's designer:

    // 
    // 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();

The error is from this line:

 this.Load += new System.EventHandler(this.Form1_Load);

回答1:


The error is telling you that you don't have a Form1_Load method in your Form1 class, and you are trying to use one.

Delete that line if you don't need to do any initialization when the form first loads, or ensure you do have one (that conforms to the signature of the EventHandler delegate).




回答2:


That means that there is no Form1_Load method anywhere inside Form1. To fix that, you either need to delete that event handler generated code or in Form1, add a Form1_Load method, for example:

 this.Load += new System.EventHandler(this.Form1_Load); // <----- REMOVE THIS

OR:

public partial class Form1
{
...
Form1_Load(object sender, System.EventArgs e)
{
// Do whatever
}
}



回答3:


Remove this:

this.Load += new System.EventHandler(this.Form1_Load);

or implement method:

private void Form1_Load(object sender, System.EventArgs e)
{
    //your code
}


来源:https://stackoverflow.com/questions/14172404/johny-form1-does-not-contain-a-definition-for-form1-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!