Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fastest way to write event handlers 2

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
0
0
US
Hi All,
What is the fastest way to write an event handler for, let's say a form (with the right signature and all) in C#. I find myself doing the following:

1 - Use the WinCV utility to find out (by looking at the Invoke method) what the correct signature of the event is.

2 - Create a method in my class (a Windows form in this case) that matches the signature of the delegate, as shown in the WinCV utility.

3 - Manually update the InitializeComponent method to register my event handler with the event delegate.

In the old days when I used to programm in Visual Basic 6, I used to (1)double click on the control to which I wanted to add an event handler, (2)select an event from a combo box, and (3)the event handler template (with the correct signature) would be created automatically as soon as I selected the event from the combo box. All I had to do was Double-Click, Select, and write code.

In C#, I'm forced to know the signature of the event delegate before I write an event handler. If I don't know it, I'm out of luck. On top of that, I have to manually register the event in the InitializeComponent method. Is there anyway to generate the template for event handlers automatically? For example, when you double-click on a Windows form, an event handler is automatically created for the Load event of the form. Can this be done automatically for other events as well?

Thanks!

JC

Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
Oh C'mon guys - I know you could do better than that!!!

JC

Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
This is one of the less obvious parts of the C# IDE. I just recently found out about it. Select a control, bring up the properties, and click on the lightening bolt (for events). From that property view, you'll be able to add events as easily as from VB.

 
Thanks Rhymes,
You have no idea how annoying it was having to figure out what the right signature for event handlers was. Thanks again!

JC

Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
There is another simpler way to do it.
It works under Visual Studio .NET Enviroment

something like

private Button b1;
...
b1=new Button();
...
type b1.OnPaint+= and then after += you just type 2 times TAB key, it will autocomplete with what you want also will point you to the right function ;)
Good luck.


________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top