C # copy, paste form into Visual Studio project

I want to create a new form that almost duplicates the dialogue that I already have in my project. I don’t want to waste time reconstructing most of the form if I don’t need to.

Copy, then paste it into your project and rename it from Copy of Original .cs to NewItem.cs .

When I rebuild my decision, I get an error .

 The item "obj\Debug\Control.Forms.NewUser.resources" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter. 

What am I doing wrong? Is there any way to solve the problem?

+7
c # resources winforms visual-studio-2005
source share
3 answers

You probably have a local resource stored in the Called Original.resx file

When you copied the dialog, he copied this file, but did not rename it (this should not happen). See if you have a .resx file under the copy of Original.cs in Solution Explorer. If so, rename it.

In any case, you should perform a cleanup (right-click on a project or solution) to clear the obj and bin folders, and then try recompiling.

+3
source share

An old question, but I will be responsible for future googlers, as the OP claimed that the accepted answer did not solve the problem.

The problem is that NewItem.cs still contains a class with the same name as Original.cs . This happens when the file name and class name are different (unlike Eclipse for Java, Visual Studio allows this in C # projects). The copied attachment adds a β€œCopy” prefix to the file name and the file rename function is not intelligent enough to realize that renaming the class would be appropriate in this case.

To fix the error, the class in the duplicated project must be renamed. I say an item instead of a file, because in the case of WinForms files, this means two files: one that by default starts the analyzer (right-click β†’ show the code or F7 if you are greeted by the visual designer) and .designer.cs. No need to modify .resx AFAIK.

+2
source share

When you create a copy of the original form, VS does not change the original namespace (in your case, it is still "Original"). Therefore, simply change this duplicate namespace (in "Copy of Original") to unique, unique objects.

0
source share

All Articles