0

The MainForm_Load doesn't work, the form is showing as I designed, but nothing in the load method happens. When I put a breakpoint it just skip on this method, I tried to delete the method and recreate it but it still not working.

I'm using Visual Studio 2010, everithing works fine with other projects I did.

Even the most basic function not working in it. Here is an example:

    public FormMain()
    {
        InitializeComponent();
    }

    private void FormMain_Load(object sender, EventArgs e)
    {
        MessageBox.Show("Test");
    }

Any ideas?? Tnx

Servy
  • 202,030
  • 26
  • 332
  • 449
user2254436
  • 491
  • 3
  • 10
  • 24

2 Answers2

6

Did you type this by hand?

You need to assign the event, if you do this on the designer it will auto generate the code. If you want to do by hand you have to manually assign the event.

public FormMain()
{
    InitializeComponent();

    this.Load += FormMain_Load;
}
BrunoLM
  • 97,872
  • 84
  • 296
  • 452
1

Everything looks fine here.Please check this.

Go to Properties window of your form(here it is FormMain.cs[Design] ). Click on event section. check in Load event your

FormMain_Load

method is defined or not ?

give the breakpoint and check it is calling or not. Give breakpoint on the form constructor .

And you need to check, From where you are calling this form ? if this form is the first form in your application, then go to Program.cs file. and check there this is available or not inside Main Function.

 Application.Run(new FormMain());

In FormMain.Designer.cs page check

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

is available inside

private void InitializeComponent()
{
}

or not?

Chandan Kumar
  • 4,570
  • 4
  • 42
  • 62
  • i tried all of it. The method in properties form is defined with the exact same name of the method (FormMain_Load). I've already checked in the designer the EventHandler as you described and it exists – user2254436 Dec 18 '13 at 17:56
  • give the breakpoint and check it is calling or not. Give breakpoint on the form constructor – Chandan Kumar Dec 18 '13 at 17:59
  • give the breakpoint and check it is calling or not. Give breakpoint on the form constructor. in program.cs inside main function do this Application.Run(new FormMain()); – Chandan Kumar Dec 18 '13 at 18:05