Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 designer code template

Like the title says: Is there a way to change the template which VS uses to create the designer file? For example the naming conventions for controls or its events. I did some research on it, but was only able to find some older posts, which were basically saying "no it's not", maybe something has changed in the last couple months or so...

I was able to identify the folder where the default templates for creating the class which is created in the beginning "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Windows Forms\1033". But I'm still searching for the template which generates the event-methods and so on...

Edit: Sorry if I mixed up my question. As Basti stated, I do look for both, changing the class template (you can do that by changig the template files, found in the VS directory C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates) and also changing the naming convention for generating fields, event-names and so on.

like image 467
DerApe Avatar asked Oct 22 '22 04:10

DerApe


1 Answers

You're asking two questions at once.
For the first question ("Is there a way to change the template which VS uses to create the designer file?"): yes, there is.
You need to find a file called Form.zip and within this file you find the relating templates.

The other question you're asking concerns the naming conventions.
As for my experience, I don't know of a way to simply change a template file in order to change naming conventions as these are two different things. Templates just describe the structure or layout of a certain type of code file (Class, Form, ...), while naming conventions have nothing to do with the structure of the file itself!

What I know of are extensions to VS, for example EventHandlerNaming. It lets you customize the standard naming of EventHandlers (internally it is using EventBindingService.CreateUniqueMethodName) - if this extension doesn't fit your needs, at least you can take a look at the sources and perhaps implement your own conventions.
Another extension would be ReSharper, which seems to allow you to create own templates and naming conventions, but I haven't tested it yet.

EDIT
The template file you're looking for (designer file for forms) should be somewhere under C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates.
For me, I find it in C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\VSTA\ItemTemplates\CSharp\1031\Form.zip (having only VS2010 installed) and within the zip are three files:

Form.zip
|-- form.cs
|-- form.designer.cs
|-- windowsform.vstemplate

The form.designer.cs is the one you're looking for, this is the template file the designer uses to generate the designer-files of forms.

Another solution to this would be to not change the original templates, but to create your very own templates. Advantage of this is - obviously - that you don't loose the original ones in case you have to fall back to them.
Information on creating custom templates can be found on MSDN or in tutorial form over on switchonthecode.net. As for the parameters/variables you're able to use in a template, there is a compilation here.

EDIT #2
Regarding the naming conventions you can take a look at StyleCop. At a first glance it looks like CheckStyle for Eclipse, a plugin/an extension enforcing code-styling. Seems like it would perfectly fit your needs.

like image 150
KeyNone Avatar answered Jan 02 '23 20:01

KeyNone