Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Visual Studio and C#: How to Visually Add Events to Controls?

How would one go about adding an event handler to a control in a form in Microsoft Visual Studio (2008) with C#?

I can do it manually, but opening the Designer.cs file for the Form, but I cannot find a way to do it through the interface.

In MSVC 6, with C++ and MFC, you could right click or some other action, and find a list of all the possible events for that control. Then you select it and it would bring up window letting you create a method to associate with that event. In VB it was even easier, you could do it in the code and it listed all the events in the method drop downs.

However, I cannot find anything of the sort in 2008 with C#. Intellisense helps fill in the correct method information. However, it always creates the method in the Designer.cs file, not the other half of the partial class where it should be.

like image 542
morrog Avatar asked Jul 16 '09 03:07

morrog


People also ask

Does Visual Studio work with C?

Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion.

Is Visual Studio an IDE for C?

Visual Studio C/C++ IDE and Compiler for Windows.


2 Answers

In the designer, click the control of interest.

In the properties window (hit F4 to bring it up), there should be a little lightning bolt icon. Clicking the icon takes you to the list of available events for that control. Double-clicking the event name will wire up a stub handler and take you to the code-behind for it.

alt text

Edit: the astute reader will see that the posted screenshot is for a web app (whups), but it's the exact same thing for a winforms app.

like image 54
womp Avatar answered Oct 06 '22 04:10

womp


All you have to do is to have the form/control open in designer view, have the control in question in focus/selected, open up the properties view and flick over to the events tab. Double click on the event that you're interested in handling.

alt text http://img222.imageshack.us/img222/4456/propv.jpg

like image 36
jpoh Avatar answered Oct 06 '22 03:10

jpoh