Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a duplicate of a form in Visual Studio 2008 (C#)

I have a form in my existing project.

My current task is to make a duplicate of an existing form and change few things on the new form. Making a copy of the form cs files would not do since the existing contents themselves refer to file information.

Simply put, I am trying to crate a form name MyNewForm, which will be a direct duplicate of MyCurrentForm without causing any naming conflict that may arise in mere copy pasting of code content.

What is the fastest way I can achieve this?

like image 276
Shamim Hafiz - MSFT Avatar asked Nov 01 '10 12:11

Shamim Hafiz - MSFT


People also ask

How do I copy one form to another project in C#?

To copy a form from one VS2013 project to another, the easiest, (fewest mouse clicks) is: In your target project, right mouse click on your parent folder (likely your project) and in the menu select, "Add; Existing Item". Then select the form's cs file in your source project.


2 Answers

Copy the form in visual studio solution explorer. Rename it. And change the class name manually both in .cs and .Designer.cs files. Do not use VS refactoring feature as it blows away references to the original class.

like image 66
Kamyar Avatar answered Oct 15 '22 05:10

Kamyar


To duplicate a form (in the same project):

  1. Right click on the source form --> Copy
  2. Right click on the destination folder/project --> Paste
  3. Right click on the new form --> Rename
  4. Change manually the class name in .cs
  5. Change manually the constructor name in .cs
  6. Change manually the class name in .Designer.cs

Enjoy!

like image 37
David Avatar answered Oct 15 '22 05:10

David