locked
Load Error in WinForms Designer RRS feed

  • Question

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

    Interestingly enough, this came up after a totally separate error was resolved - the previous error was regarding a button with an extra "click" attribute, I must have double clicked the button twice.

    But the thing is, the problem lies with the form loading pre-adjustment... does this happen to other people?  I've resized the form and it won't display the new arrangement.

    Here is the current line of code the error refers to, btw.

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

    Monday, April 13, 2015 12:28 AM

Answers

  • Hi TheRedGuy,

    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,

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

    OR add a Form1_Load method.

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

    Best regards,

    kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Tuesday, April 14, 2015 5:21 AM
    • Marked as answer by TheRedGuy1990 Tuesday, April 14, 2015 6:05 PM
    Tuesday, April 14, 2015 5:20 AM

All replies

  • That line is trying to subscribe to the form's load event. That is, when the form is loading it will try to call a method called Form1_Load. The error is saying that this method does not exist.

    Usually when this happens, it's because the developer double-clicked on the load event in the designer, then changed his/her mind and deleted the method but forgot to delete the line subscribing to the event.

    Monday, April 13, 2015 1:41 AM
  • Did I do this??  I never touched anything in the designer, except deleting a line regarding a button click.

    I believe is was something like "button_click1" when there was a "button_click" already, so I thought it was redundant.

    Monday, April 13, 2015 6:30 PM
  • Hi TheRedGuy,

    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,

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

    OR add a Form1_Load method.

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

    Best regards,

    kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Tuesday, April 14, 2015 5:21 AM
    • Marked as answer by TheRedGuy1990 Tuesday, April 14, 2015 6:05 PM
    Tuesday, April 14, 2015 5:20 AM