Common Event Types in C# WinForms

Click, TextChanged, Load and more in WinForms

Events are the heartbeat of a Windows Forms application. They tell your app when the user clicks a button, types in a box, or opens a form β€” and they let you respond with code.

Let’s explore the most useful events you’ll use again and again.


🧰 What Are Events?

In WinForms, events are triggers that respond to user actions or application changes. When an event fires, your attached method β€” the event handler β€” runs automatically.


πŸš€ Getting Started

Every control in WinForms has its own set of events. You can:

  • Double-click a control in the designer to auto-generate a handler
  • Or connect one manually:
button1.Click += MyClickHandler;

πŸ”˜ Click β€” Button Presses & More

One of the most common events. Fires when the user clicks a control like a Button, Label, or even a Form.

private void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show("Button was clicked!");
}

βœ… Used for: Submitting forms, triggering actions, navigation


πŸ“ TextChanged β€” Detecting Input Updates

Fires whenever the text inside a TextBox, RichTextBox, or similar control changes β€” including from code!

private void textBox1_TextChanged(object sender, EventArgs e)
{
    label1.Text = "You typed: " + textBox1.Text;
}

βœ… Used for: Live validation, search filters, character counters


πŸͺ„ Load β€” Run Code When the Form Starts

Fires once, when the form first loads. Ideal for setup code, default values, or pre-loading data.

private void Form1_Load(object sender, EventArgs e)
{
    comboBox1.Items.AddRange(new string[] { "Red", "Green", "Blue" });
}

βœ… Used for: Populating controls, setting initial values, reading from files or databases


⌨️ Other Common Events

EventFired When…Typical Use
CheckedChangedCheckbox or radio button is toggledSettings toggles, form options
SelectedIndexChangedA new item is selected in a ComboBoxUpdate UI based on selection
KeyDown / KeyPressA key is pressed while a control is activeKeyboard shortcuts, input validation
MouseEnter / MouseLeaveCursor moves over or off a controlTooltips, hover effects
FormClosingUser closes the formConfirm save, cleanup, autosave

βš™οΈ Example: Live Feedback Form

private void textBoxName_TextChanged(object sender, EventArgs e)
{
    labelGreeting.Text = "Hello, " + textBoxName.Text + "!";
}

private void buttonSubmit_Click(object sender, EventArgs e)
{
    MessageBox.Show("Submitted: " + textBoxName.Text);
}

πŸ’‘ Add this to the form’s Load event:

labelGreeting.Text = "Type your name above.";

πŸ§ͺ Quick Challenge

🧩 Create a form with:

  • 1 TextBox for the name
  • 1 Button to submit
  • 1 Label to greet the user live

Expected behavior:

  • Typing updates the greeting in real time
  • Clicking the button shows a message box

πŸ“š Summary

EventDescription
ClickRuns code when user clicks a control
TextChangedDetects text updates in input fields
LoadRuns once when form is first shown
FormClosingFires when app window is closing
KeyPressRuns on key input (with character info)

πŸŽ“ What’s Next?

  • βœ… Combine multiple events for smart forms
  • βœ… Use timers for live updates
  • βœ… Handle file saving in FormClosing
  • βœ… Trigger sounds or animations on Click

πŸ’¬ Have a form you want to wire up with events?
Let me help you plan it out or troubleshoot your handlers!