Davees John Baclay
Davees John Baclay

Reputation: 89

Where can I find the event handlers in C#

In VB.NET I can simply find the event handler of an object in the upper right corner while I can't find it on C#, can anyone help me please? Thanks in advance

enter image description here

enter image description here

Upvotes: 0

Views: 3342

Answers (1)

Peter Duniho
Peter Duniho

Reputation: 70671

There is no such feature in the IDE for C#. C# does not have the Handles keyword like VB.NET, and event subscription is done in a more explicit way.

The closest similar feature is when you are editing a Form or UserControl object with the Windows Forms Designer. When an object is selected in the Designer, the Properties window can show you either the properties of the object or its events, depending on which you have selected in the Properties window's toolbar.

Properties window with Events button circled

When it's displaying events, you can see the events declared for that object. If a handler is assigned to the event, it will be displayed. If you click on the drop-down arrow where the handler is displayed, you'll see a list of methods in the container class (Form or UserControl) that you are editing which are eligible to be subscribed to that event.

Properties window with Events drop-down displayed

Note that the above is only for Windows Forms Designer editing. WPF has a completely different Designer which operates similarly (i.e. has an "events" mode in the Properties window while using the Designer). Other events declared and used in code are not displayed in the manner you're used to at all. All you get in a C# editing window is the class member drop-down in the navigation bar of that editing window, where you can find events, methods (whether those methods handle events or not), and other class members, in alphabetic order.

Upvotes: 1

Related Questions