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

10,620

Solution 1

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.

Solution 2

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.

Share:
10,620
Kevin
Author by

Kevin

self-taught protege

Updated on June 04, 2022

Comments

  • Kevin
    Kevin almost 2 years

    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?