Ahmed
Ahmed

Reputation: 15029

On What event should I assume Windows Form is visible?

In a C# app which is windows Form based not WPF. I need to show an IP/port dialog to the user right after the main form is shown to user.

Based on the connection to a server I need to show certain controls on the Form and disable others.

What's the best place to do that ?

I started with Activated event, but it's called every time Form gets activate. Is there any method that's tells me form is now showing and I can show the connection form now?

Upvotes: 4

Views: 2532

Answers (2)

ChrisF
ChrisF

Reputation: 137108

The Form.Shown event is fired when the form is first shown. This will only get fired the once.

The Form.Load event is fired each time the form is loaded. This will get fired each time the form is shown. If the form is the main (or only) form in your application then this will only fire the once. If the form is a sub form (or dialog) then it will fire each time the dialog is opened.

The Form.Activated event is fired each time the form becomes the active form. This could potentially happen several times during the lifetime of the form. It will fire for the main form when any sub form (or dialog) is closed.

Upvotes: 9

Sidharth Mudgal
Sidharth Mudgal

Reputation: 4264

You are looking for the Form.Shown event, if I understand correctly.

Upvotes: 1

Related Questions