Kevin
Kevin

Reputation: 3623

C# copy, paste a form in a Visual Studio project

I want to create a new form that is almost a duplicate of a dialog I already have in my project. I don't want to waste time recreate most of the form scratch if I don't have to.

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

When I goto rebuild my solution, 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 a way to fix the problem?

Upvotes: 7

Views: 11441

Answers (3)

Emperor Orionii
Emperor Orionii

Reputation: 752

Old question but I'll answer for future googlers since OP claimed that accepted answer didn't resolve the problem.

Problem is that NewItem.cs still contains a class with the same name as Original.cs. This happens when file name and class name are different (unlike Eclipse for Java, Visual Studio allows that in C# projects). Copy-pasting appends "Copy of " prefix to the file name and rename file feature is not intelligent enough to figure out that renaming the class would be appropriate in such case.

To fix the error, the class in duplicated project item has to be renamed. I say item instead of file because in the case of WinForms stuff, that means two files: one that solution explorer displays by default (right click -> show code or F7 if you are greeted by visual designer) and the .designer.cs. There is no need to modify .resx AFAIK.

Upvotes: 2

tnhan07
tnhan07

Reputation: 1187

When create the copy of Original form, VS don't change the original namespace ( in your case, it's still "Original"). So, just change this duplicated namespace(in "Copy of Original") into somethings unique.

Upvotes: 0

Simon Mark Smith
Simon Mark Smith

Reputation: 1160

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

When you copied the dialog it copied this file but did not rename it (this should not happen though). See if you have a .resx file beneath your Copy Of Original.cs in the Solution Explorer. If so rename this also.

Might be worth performing a Clean (right-click on the Project or Solution) anyway to clear out the obj and bin folders, then try a recompile.

Upvotes: 3

Related Questions