How to create a custom code template in Visual Studio 2005 or in Visual Studio .NET (870715)



The information in this article applies to:

  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual C# 2005, Express Edition
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)

INTRODUCTION

This step-by-step article describes how to create a custom code template in a Microsoft Visual C# 2005 or Microsoft Visual C# .NET Windows application project and then add it to the Visual Studio 2005 or Visual Studio .NET IDE.

back to the top

MORE INFORMATION

To create a custom code template in a Microsoft Visual C# 2005 or Microsoft Visual C# .NET Windows application project and then add it to the Visual Studio 2005 or Visual Studio .NET IDE, follow these steps.

Change the LocalProjectItems.vsdir file

  1. Right-click My Computer, and then click Explore.
  2. Locate the LocalProjectItems folder.

    In Microsoft Visual Studio .NET 2003, the folder is located in the following path:
    C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems\LocalProjectItems

    In Microsoft Visual Studio .NET 2002, the folder is located in the following path:
    C:\Program Files\Microsoft Visual Studio .NET\VC#\CSharpProjectItems\LocalProjectItems

    Note C represents the hard disk drive where you installed Visual Studio .NET.
  3. Create a new MyCustomTemplates folder in the LocalProjectItems folder.
  4. Copy the LocalProjectItems.vsdir file to the MyCustomTemplates folder.

    In Microsoft Visual Studio .NET 2003, the LocalProjectItems.vsdir file is located in the following path:

    C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems\LocalProjectItems

    In Microsoft Visual Studio .NET 2002, the LocalProjectItems.vsdir file is located in the following path:

    C:\Program Files\Microsoft Visual Studio .NET\VC#\CSharpProjectItems\LocalProjectItems

  5. In the MyCustomTemplates folder, open the LocalProjectItem.vsdir file by using Notepad, and then replace the existing text with the following text:

    ..\..\MyCustomTemplatesWinFormWiz.vsz|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|#2237|10|#2264|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|4535|0|Form.cs

  6. Save the file, and then quit Notepad.
back to the top

Create a custom Windows form wizard

  1. Open the CSharpProjectItems folder.

    In Visual Studio .NET 2003, the folder is located in the following path:

    C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\CSharpProjectItems

    In Visual Studio .NET 2002, the folder is located in the following path:

    C:\Program Files\Microsoft Visual Studio .NET\VC#\CSharpProjectItems

  2. Copy the CSharpAddWinFormWiz.vsz file to the CSharpProjectItems folder, and then rename the file to MyCustomTemplatesWinFormWiz.vsz.
  3. Open the MyCustomTemplatesWinFormWiz.vsz file by using Notepad, and then change the wizard name parameter value to the following:

    Param="WIZARD_NAME = MyCustomTemplatesWinFormWiz"

  4. Save the file, and then quit Notepad.
back to the top

Create a custom Windows form template

  1. Open the VC#Wizards folder.

    In Visual Studio .NET 2003, the folder is located in the following path:

    C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards

    In Visual Studio .NET 2002, the folder is located in the following path:

    C:\Program Files\Microsoft Visual Studio .NET\VC#\VC#Wizards

  2. Copy the CSharpAddWinFormWiz folder to the VC#Wizards folder, and then change the name of the the CSharpAddWinFormWiz folder to MyCustomTemplatesWinFormWiz.
  3. Double-click the MyCustomTemplatesWinFormWiz folder, open the Templates folder, and then double-click the 1033 folder.
  4. Open the NewWinForm.cs file by using Notepad.
  5. Add the lines of code that you use frequently to the top of the NewWinForm.cs file.
  6. Save the file, and then quit Notepad.
back to the top

Open the template in Visual Studio .NET

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click Visual C# Projects.
  4. Under Templates, click WindowsApplication.
  5. Click OK. By default, the Form1 form appears.
  6. On the Project menu, click Add New Item. The Add New Item - Your Windows Application dialog box appears.

    Note Your Windows Application is a placeholder for the name of the Windows application that you created.
  7. Under Categories, expand Local Project Items, click MyCustomTemplates, and then click Open. By default, the Form2.cs file is created.
  8. Right-click the Form2 form, and then click View Code.
  9. The code that you see is the code that you added in step 5 of the "Create a custom Windows form template" section.
back to the top

REFERENCES

For more information, visit the following Microsoft Web site:

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

320985 How to add a CSS style sheet reference to all Web forms in a Visual C# .NET Web project

323843 How to add a CSS style sheet reference to all Web forms in a Visual Basic .NET Web project

back to the top

Modification Type:MajorLast Reviewed:2/14/2006
Keywords:kbvs2005swept kbvs2005applies kbHOWTOmaster kbhowto kbWindowsForms kbTreeView kbView kbsettings KB870715 kbAudDeveloper