469,616 Members | 1,737 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Form Load Event Behavior...

I am experiencing some unexpected behavior with the Form Load event in a
Windows application. Hopefully, someone can explain why this behavior is
occurring.

In my application, I have a form that I would like to show multiple times
throughout the life of the application. The startup code for this form can
be quite lengthy so I am hiding and showning the form (versus unloading and
loading it). If I show the form non-modally (using the Show method), the
code in the Load event is fired only one time. If I show the form modally
(using the ShowDialog method), the code in the Load event is fired every time
I make the form visible.

Is there an explanation as to why this behavior is occuring?

Thank you,

Jason Richmeier
Apr 25 '06 #1
1 2004
Hi Jason,

Thank you for posting.

As you know, it's different for a winform to display modal or modeless.

Firstly, if a winform is loaded for the first time, whether in the modal
mode or modeless mode, the load event of the winform will be raised.

Secondly, after the winform is shown modeless, the program control will
return to the place where the sentence called to open the form is and the
code following this sentence will be executed. On the contrary, if the
winform is shown modal, the code following the sentence will not executed
until the winform is closed.

Thirdly, if you hide a modeless winform , the winform will be invisible but
not be unloaded. While if you hide a modal winform , the winform will be
invisible and unloaded but not disposed. The code following the sentence
that showes the winform in the modal mode will be executed now. Then if
you show a modeless winform again, the winform will be visible again but
the load event will not be raised. While if you show a modal winform
again, the winform will be loaded again and the load event will be raised.

Hope I am making sense.

If you have any other concerns or need anything else, please don't hesitate
to tell me.

Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Apr 26 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by MrNobody | last post: by
3 posts views Thread by Matt | last post: by
7 posts views Thread by Tyler Foreman | last post: by
7 posts views Thread by =?Utf-8?B?bGpsZXZlbmQy?= | last post: by
6 posts views Thread by Steve | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.