O'Reilly logo

Visual Studio® 2010 All-in-One For Dummies® by Rick Leinecker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Wiring Up Events in the User Interface

In This Chapter

  • Understanding events and event handlers

  • Using Visual Studio to discover events

  • Creating event handlers with Visual Studio

  • Getting a grip on Windows and Web applications life cycles

Code fires in response to events, such as button clicks. Taking advantage of the events in an application and control life cycles allows you to run code at a precise moment in an application's or a control's life cycle. Instead of waiting for a user to click a button, you can run code as soon as your application starts — or even when a user's cursor leaves a text box.

In Visual Studio, responding to events is as simple as a double-click, in many cases. Visual Studio generates codes behind the scenes that wire up your code to the event that fires it.

Handling Events

In most modern applications, an application responds to actions that a user takes. Your application sits in a waiting state until a user comes along and clicks a button, a menu, or a drop-down list. When a user clicks a button, an action (the event) occurs. The code that executes when an event fires is an event handler.

Procedures that run when an event occurs — event handlers — um, handle events. Still, they're just procedures, just like any procedure you write. You're responsible for writing event handlers to handle any events to which you wish to respond.

For example, say that you want a message box to pop up when a user clicks OK on your Windows Form. The following code sample uses ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required