How to execute code in Load event when .hide

ldjpr

Member
Joined
Jan 11, 2009
Messages
7
Programming Experience
3-5
Hello

I have some code that currently executes when the form loads. I need for the same code to execute when the form is shown. How could I accomplish this if the load event only triggers when the form is loaded?

My flow is:
1. create form - load executes
2. hide form
3. show form

Where can I find the order of the events of a Win form?

Thanks

ld
 
The Form has Load, Shown and Activated events. Load is raised BEFORE the form is displayed for the FIRST time. Shown is raised AFTER the form is displayed for the FIRST time. Activated is raised EVERY time the form receives focus.
 
I have an application that has multiple forms and the application flow uses then in a sequence. There is one form that when I finish using it I don't close it but hide it. I need certain code to execute EVERY TIME the form is displayed on screen. I can't use load or shown as it only executes once the first time the form is loaded and activated executes repetitively. What event I could use?

I need the code to execute only once every time the .show is is executed.

Any suggestions?

ld
 
There isn't an event for you to use that does that, what you need to do is use the Activated event and use variables to determine when the code should run in the event

Edit:
Another thought would be to use the Visible changed event and in there the only thing you'd need to do is only have it run the code if it's not the first time running.
 
Thanks Juggalo. Took the approach of using Visible_changed event. Have to setup a varaible so it is eecuted only once because the event is raised when the form is shown and hiden.

regards

ld
 
Thanks Juggalo. Took the approach of using Visible_changed event. Have to setup a varaible so it is eecuted only once because the event is raised when the form is shown and hiden.

regards

ld
All you need to do is test the value of the Visible property inside the event handler. If it's True then you know that the form was just shown. If it's False you know the form was just hidden. The whole point of the VisibleChanged event is to notify you when the Visible property value changes.
 
Back
Top