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

24,417

Solution 1

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.

Solution 2

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!

Solution 3

Why do you need to make a duplication of the form? Try to find some refactoring that can help you, e.g. create some base form and extract common logic there.
Every time you make a duplication kitten dies!

Share:
24,417
Shamim Hafiz - MSFT
Author by

Shamim Hafiz - MSFT

Help and get helped

Updated on August 16, 2020

Comments

  • Shamim Hafiz - MSFT
    Shamim Hafiz - MSFT almost 4 years

    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?