The order in
which events are raised in Windows Forms applications is of particular interest
to developers concerned with handling each of these events in turn. When a
situation calls for meticulous handling of events, such as when you are
redrawing parts of the form, an awareness of the precise order in which events
are raised at run time is necessary. This topic provides some details on the
order of events during several important stages in the lifetime of applications
and controls.
Application Startup and Shutdown Events
The Form and Control classes expose a set of events related to application startup and shutdown. When a Windows Forms application starts, the startup events of the main form are raised in the following order:
· Control.HandleCreated
· Control.BindingContextChanged
· Form.Load
· Control.VisibleChanged
· Form.Activated
· Form.Shown
When an application closes, the shutdown events of the main form are raised in the following order:
· Form.Closing
· Form.FormClosing
· Form.Closed
· Form.FormClosed
· Form.Deactivate
Application Startup and Shutdown Events
The Form and Control classes expose a set of events related to application startup and shutdown. When a Windows Forms application starts, the startup events of the main form are raised in the following order:
· Control.HandleCreated
· Control.BindingContextChanged
· Form.Load
· Control.VisibleChanged
· Form.Activated
· Form.Shown
When an application closes, the shutdown events of the main form are raised in the following order:
· Form.Closing
· Form.FormClosing
· Form.Closed
· Form.FormClosed
· Form.Deactivate
Windows Forms
Event Sequence
Form Start up
Event
|
Description
|
|
1.
|
Control.HandleCreated
|
Occurs when
a handle is created for the control.
|
2.
|
Control.BindingContextChanged
|
Occurs when
the value of the BindingContext property changes.
|
3.
|
Form.Load
|
Occurs
before a form is displayed for the first time.
|
4.
|
Control.VisibleChanged
|
Occurs when
the Visible property value changes.
|
5.
|
Form.Activated
|
Occurs when
the form is activated in code or by the user.
|
6.
|
Form.Shown
|
Occurs
whenever the form is first displayed.
|
Form Shutdown
Event
|
Description
|
|
1.
|
Form.Closing
|
Occurs when
the form is closing.
|
2.
|
Form.FormClosing
|
Occurs
before the form is closed.
|
3.
|
Form.Closed
|
Occurs when
the form is closed.
|
4.
|
Form.FormClosed
|
Occurs
after the form is closed.
|
5.
|
Form.Deactivate
|
Occurs when
the form loses focus and is no longer the active form.
|
No comments:
Post a Comment