I agree with John, it seems poorly structured.
However, that being said, it worked fine for me:
private void Form1_Load(object sender, System.EventArgs e)
{
Console.WriteLine("Form Load");
MessageBox.Show("Hi");
this.Close();
}
A better solution:
Add a method to your Form called:
public bool ShouldShow()
And use that before calling Show().
Or you could try using the VisibleChanged event. Unfortunately, in an
example I ran, the VisibleChanged event fires after the Load event
Finally, you could declare a new Show() method that either display a
message box or else calls base.Show(). Note, however, that Show is
not declared virtual, so Application.Run(myForm) will not call your
method polymorphically.
mike
"John Wood" <j@ro.com> wrote in message
news:Os**************@TK2MSFTNGP09.phx.gbl...
It sounds like this might be more of a design issue than anything.
You probably want to catch that exception (the instance where you show
the messagebox rather than displaying the form) BEFORE you load the form
by doing the .Show().
"David Smith" <no****@here.net> wrote in message
news:3f********@news.athenanews.com... Under a certain circumstance, I want a form to display a
messagebox in the load event, and then close. But apparently I cant close a form in
the load event. Any ideas?
Thanks