EventHandler Naming extension for Visual Studio 2010

EventHandler Naming extension by Einar Egilsson lets you customize the name format for event handlers automatically generated by Visual Studio 2010.

When you subscribe to a control event in the C# Windows Forms designer, Visual Studio generates a method for you in the button1_Click name format. It is hard to imagine a coding standard that accepts this naming convention. EventHandler Naming lets you change this, for example, to OnButton1Click.

In EventHandler Naming options, accessible from the ToolsEvent Handler Naming menu item, you can customize the name pattern and case for the site/event names:

EventHandler Naming Options dialog

EventHandler Naming Options dialog

Site and event name case options

Site and event name case options

If you use type prefixes for your controls like lbl or btn, EventHandler Naming can remove them from a handler name. For form event handlers like OnForm1Load, EventHandler Naming can remove the form name and generate just OnLoad if you check the Omit $(SiteName) for own events option.

Functionality described above works for Windows Forms and Web Forms designers in C#, Visual Basic and C++/CLI projects. The WPF/XAML designer is not supported because it lacks needed extensibility points.

There is one more place when Visual Studio generates event handlers for you. If you are manually subscribing for an event in C# and type, for example, button1.DragDrop +=, Visual Studio prompts you to press TAB to generate an event handler method. EventHandler Naming supports this scenario as well. Plus, if you check the Use delegate inference option, instead of button1.DragDrop += new DragEventHandler(OnButton1DragDrop); more shorter code will be generated: button1.DragDrop += OnButton1DragDrop;.

EventHandler Naming is a free extension for Visual Studio 2010. You can download it from Visual Studio Gallery. Source code is available on GitHub.

This entry was posted in Reviews and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s