Tag Archives: winform template

How to duplicate a winform in Visual Studio easily

You start with a new project and you have created a winform with graphics and the functionality which you want to use in all your other forms in the same project.

One would think that it is easily done as we can simply copy and paste the existing form and rename it and then suddenly all will be well.

That is not the case when you Control C and Control V to copy the form. You will try to rename it but you might gets lots of errors. I have struggled with this may times.

I have discovered a fool proof way which works well.

There is an Export Functionality in Visual Studio which is handy. This functionality allows you to create a template and resuse the template form in your project .

Step 1

Go to File> Export Template in Visual Studio

Step 1
Step 1

 

Step 2

Step 2
Step 2

Select ITEM Template, You can also choose Project Template ( which will appear only in  your existing project).

where as ITEM template would be universally available for all new  or existing projects.

Step 3

 

Select the form which you want to clone

Step 3
Step 3

 

Step 4

 

You might need to select the references which you want to be included, select the ones which you think will need. You can always add them later using the code in your project  using the USING command  in C# or IMPORTS command in VB.NET after you have cloned a form.

Step 4
Step 4

 

Step 5

 

Provide a new name and some useful description to your new template.

Step 5
Step 5

Step 6

 

when you click on Finish in Step 5 the new template will be created in the Windows Folder as you can see below.

Step 6
Step 6

 

Step 7

 

When you click on ADD NEW ITEM in your Visual Studio project you should be able to see you newly created Template. You can use this template whenever there is a need . I found this approach simpler and safer than merely copying and pasting an existing form.

Step 7
Step 7