Form Load Event Behavior...

G

Guest

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
 
L

Linda Liu [MSFT]

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.
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top