Where to put code to have it execute only when form actually comes up(i.e. is visible)

B

BobRoyAce

I have code that I want to execute as soon as the form comes up. This
code includes code that shows a status form indicating processing
activity, a form that immediately closes once the processing activity
is completed. I can't call it from the Load event as it will execute
before the form is visble. Where is the best place to put code like
this? I thought that perhaps the place would be in the VisibleChanged
event. However, if I put it there, it still executes before the form
is visible.
 
A

Armin Zingler

BobRoyAce said:
I have code that I want to execute as soon as the form comes up. This
code includes code that shows a status form indicating processing
activity, a form that immediately closes once the processing activity
is completed. I can't call it from the Load event as it will execute
before the form is visble. Where is the best place to put code like
this? I thought that perhaps the place would be in the VisibleChanged
event. However, if I put it there, it still executes before the form
is visible.

Which .Net version? Since 2.0 you can use the Form's "Shown" event.

If the first Form is not shown modally (ShowDialog), I'd instead use this
code:

firstform.show
secondform.show(dialog)
'if it's in sub main and secondform is shown modally, additionally call
'application.run(firstform) here.

One could also ask, if secondform is shown modally, why not show
secondform first before showing firstform? Firstform isn't operatable anyway
and maybe is also hidden (partially) behind secondform.


Armin
 
J

Josip Medved

I have code that I want to execute as soon as the form comes up. This
code includes code that shows a status form indicating processing
activity, a form that immediately closes once the processing activity
is completed. I can't call it from the Load event as it will execute
before the form is visble. Where is the best place to put code like
this? I thought that perhaps the place would be in the VisibleChanged
event. However, if I put it there, it still executes before the form
is visible.

You may wish to try "Shown" event.
 
B

BobRoyAce

Which .Net version? Since 2.0 you can use the Form's "Shown" event.

Well, would ya look at that...a Shown event! Now that's cool! Never
noticed that one as I was still living in pre-.NET 2.0 way of
thinking, I guess.
If the first Form is not shown modally (ShowDialog), I'd instead use this
code:

firstform.show
secondform.show(dialog)

That's what I'm doing...
One could also ask, if secondform is shown modally, why not show
secondform first before showing firstform? Firstform isn't operatable anyway
and maybe is also hidden (partially) behind secondform.

Good point except that, in this case, secondform is not only shown
modally when firstform has loaded. It's also shown modally when user
clicks on certain buttons on the form itself.
 

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

Top