Amal
Amal

Reputation: 586

Events before form showing?

Is there any event or any other notification we can get, before a windows form is loaded?

I want to process some code, before the form is loaded.

Upvotes: 0

Views: 1633

Answers (3)

Adarsh Ravi
Adarsh Ravi

Reputation: 953

Like the others said you could definitely use the Form Load event to run the code before the form is loaded and another way would be to run the code in the Main function in Program.cs which is where the control to your application starts. And this is if your code has nothing to do with the UI of the initial form.

Upvotes: 0

DesertFox
DesertFox

Reputation: 808

Official documentation

I'm not sure what you mean by "while the form is showing". I suppose it means "Just before the form starts rendering".

And for that, I would recommend:

Form Load event

And for further reference:

Win Forms chain of events

Upvotes: 4

TcKs
TcKs

Reputation: 26632

The Load event is fired just in time when form is showing. However, the form is not yet visible.

But don't forget, any computation in UI thread will prevent any UI code to be processed. In result "process some code while the form is showing" will be "stop the showing until some code is processed".

Upvotes: 2

Related Questions