Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 609
Kevin Avatar asked Feb 11 '10 21:02

Kevin


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


2 Answers

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.

like image 97
Simon Mark Smith Avatar answered Sep 18 '22 14:09

Simon Mark Smith


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.

like image 24
Emperor Orionii Avatar answered Sep 22 '22 14:09

Emperor Orionii