Form.Load Event not raised when using Form.Show, but raised when using Form.ShowDialog

113 Views Asked by At

When I open a Form via Form.Show() the Show Event of the opened form is not raised.

But when I use Form.ShowDialog(), the event is raised and my breakpoint is hit in my Form_Shown method.

I saw this answer, that an exception hides the Event, but I get no exception.

So, why is the Event raised when I call ShowDialog(), but not if I call Show()?

Here is the link to a demo. When I click on the ShowDialog() button I see the messagebox with the load and shown-event, but for Show() I only see the load Event.

1

There are 1 best solutions below

3
LarsTech On BEST ANSWER
using (var form = new Form2())
{
  form.Show();
}

The Using block will dispose of your form immediately since Show will not block the code. ShowDialog will block the code until the form is closed, hence, that version works.