CC103 – Intermediate Programming Introduction to GUI using winforms
Events. An event is something that happens while a program is running; like when a user clicks a button, types
in a textbox, or moves the mouse.
An event, by itself, doesn’t do anything. Instead, it can trigger a response if we write code to handle it. This
response is called event handling.
SPECIFIC EVENTS
Form
Event Description
Load Occurs when the form is loaded for the first time.
FormClosing Occurs before the form is closed.
FormClosed Occurs after the form is closed.
Shown Occurs after the form is displayed for the first time.
Activated Occurs when the form becomes the active window.
Deactivate Occurs when the form loses focus.
Resize Occurs when the form is resized.
ResizeBegin Occurs when a form resize operation starts.
ResizeEnd Occurs when a form resize operation ends.
Label
Event Description
Labels mostly use common events like Click, MouseEnter, etc., but they typically
(None are truly exclusive)
don’t have their own unique events.
You can still use many common events with labels (like Click, MouseHover,
Note
MouseLeave), but these are shared with other controls.
TextBox
Event Description
TextChanged Occurs when the text in the textbox is changed.
MultilineChanged Occurs when the Multiline property value changes.
AcceptsTabChanged Occurs when the AcceptsTab property changes.
ReadOnlyChanged Occurs when the ReadOnly property value changes.
HideSelectionChanged Occurs when the HideSelection property changes.
Button
Event Description
This is a method that programmatically raises the Click event; most often associated
PerformClick()
with buttons.
Like labels, buttons mostly use common events like Click, MouseEnter, KeyDown,
(No exclusive event)
etc.
CC103 – Intermediate Programming Introduction to GUI using winforms
COMMON EVENTS
Common Events in WinForms Controls
Event Name Description
Click Occurs when the control is clicked.
DoubleClick Occurs when the control is double-clicked.
MouseEnter Occurs when the mouse pointer enters the control area.
MouseLeave Occurs when the mouse pointer leaves the control area.
MouseMove Occurs when the mouse pointer moves over the control.
MouseDown Occurs when a mouse button is pressed while the pointer is over the control.
MouseUp Occurs when a mouse button is released over the control.
KeyDown Occurs when a key is pressed while the control has focus.
KeyUp Occurs when a key is released while the control has focus.
KeyPress Occurs when a key is pressed and released (character input).
Enter Occurs when the control receives input focus.
Leave Occurs when the control loses input focus.
GotFocus Occurs when the control gains focus (older alternative to Enter).
LostFocus Occurs when the control loses focus (older alternative to Leave).
TextChanged Occurs when the Text property of the control is changed.
BackColorChanged Occurs when the BackColor property changes.
ForeColorChanged Occurs when the ForeColor property changes.
VisibleChanged Occurs when the control's Visible property is changed.
EnabledChanged Occurs when the control's Enabled property is changed.
SizeChanged Occurs when the control's Size changes.
LocationChanged Occurs when the control's Location changes.
Paint Occurs when the control needs to be redrawn.