Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of events 'Form.Load', 'Form.Shown' and 'Form.Activated' in Windows Forms

What is the difference between form Form.Load, Form.Shown and Form.Activated events? What is the order in which they are fired?

like image 861
Ananth Avatar asked Jun 18 '10 13:06

Ananth


People also ask

What is the sequence of form events?

The BeforeInsert (form) event triggers as soon as you start typing in the control. The AfterInsert (form) event triggers after you leave the record. The BeforeUpdate and AfterUpdate events for the controls on the form and for the new record occur after the BeforeInsert event and before the AfterInsert event.

Which of the following is correct order of event execution for form life cycle?

The order would be Form. Load , which initializes the form and calls the controls, Form.

Which event occurs before the form is displayed?

Load: This event occurs before a form is displayed for the first time.

Which event is triggered while form loads?

The load event is called once all the components of the form are loaded. If you redisplay the form, its components load again and therefore the Load event is triggered once more.


2 Answers

See the Windows Forms Events Lifecycle:

  • Move: This event occurs when the form is moved. Although by default, when a form is instantiated and launched, the user does not move it, yet this event is triggered before the Load event occurs.
  • Load: This event occurs before a form is displayed for the first time.
  • VisibleChanged: This event occurs when the Visible property value changes.
  • Activated: This event occurs when the form is activated in code or by the user.
  • Shown: This event occurs whenever the form is first displayed.
  • Paint: This event occurs when the control is redrawn.
  • Deactivate: This event occurs when the form loses focus and is not the active form.
  • Closing: This event occurs when the form is closing.
  • Closed: This event occurs when the form is being closed.
like image 143
Galwegian Avatar answered Sep 22 '22 18:09

Galwegian


  • The Load event fires when the form has been initialized, after its handle has been created but before it is shown.

  • The Shown event fires after the first time the form becomes visible, when you call form.Show() (or form.Visible = true).
    If you hide your form, then show it again, Shown will fire again. (But Load won't)

  • The Activate event fires when the user switches to your form.
    If the user switches to a different program (or form), then switches back to your form, Activate will fire again.

like image 27
SLaks Avatar answered Sep 20 '22 18:09

SLaks