Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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!

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!

You can just add a new blank form and then select all items on the original aform and paste them onto the new form. This will not copy the code behind though. But that can also be solved with copy paste.

This will not cause any renaming conflicts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top