What event takes place after a form is loaded and displayed?

emaduddeen

Well-known member
Joined
May 5, 2010
Messages
171
Location
Lowell, MA & Occasionally Indonesia
Programming Experience
Beginner
Hi Everyone,

Can you tell me what event takes place after a form is loaded and displayed including all controls on that form?

I wish to place some code in there at that time.

Thanks.

Truly,
Emad
 
I am afraid it's irrelevant in this situation unless he Activates the form himself in code.
Actually i was aware of the Shown event as well but, according his explanation it seemed that both can apply.
So yes you can use Activated here too.

Shown will be raised once only, while Activated can be raised multiple times. The original questions strongly implies that Shown is the only suitable option.
 
Shown will be raised once only, while Activated can be raised multiple times. The original questions strongly implies that Shown is the only suitable option.

Would you mind if i ask you to create a new form and add Console.WriteLine("Activated raised") within the Activated event. Then run the project and see how many times it raises. Thanks
 
Would you mind if i ask you to create a new form and add Console.WriteLine("Activated raised") within the Activated event. Then run the project and see how many times it raises. Thanks
You can activate a form/window many times as you switch between multiple active forms/applications, but it is only Load/Shown once. :)
 
Would you mind if i ask you to create a new form and add Console.WriteLine("Activated raised") within the Activated event. Then run the project and see how many times it raises. Thanks

You can ask but I'm not going to do it because I already know. Activated will be raised as many times as the form is activated, which is every time the form gains focus, which might be many, many times in the life of the form.

Use the right tool for the job. In .NET 1.x there was only Load and Activated, so if you wanted to execute some code immediately after the form was displayed the first time and ONLY the first time, you had to handle Activated and use a Boolean flag to stop the code being executed on any but the first Activated event. That's the very reason they added the Shown event in .NET 2.0: so that you have an event that is raised only once, immediately after the form is displayed for the first time.
 
Back
Top