not able to change name after copying a form - c#

I'm trying to copy and past a form within a project using Visual Studio.
I've managed to copy and past the form (right clicking in the Solution explorer > Copy; Right click again paste) I can change the name of the new form in the Solution explorer. But when I select the form [Design] I can't change the name property without changing the name property in the original form. Somehow the two are linked. What am I doing wrong?
I hope this all makes sense.

Exclude all files of that form from project and then include again.
You can perform the include steps after reopen the project.

Related

I can't find the form that I built

I'm using Visual Studio 2013 and I created a windows form application. Everything was fine until just now. When I go into my project now I cannot find the Form1.cs [Design] tab which allows actual form designing with the rag and drop of object from the toolbox.
I checked the directory and I do have files and sub-directories, but being a C# beginner, I'm not too familiar with what files are needed.
So, could someone please show me how to get this back?
Thanks.
This is pretty vague. But if it isn't in your solution explorer, re add the files to the project.
Right Click on your project root -> New -> From Existing Item, navigate to said item and add it. (shortcut is Shift + Alt + A).
If it's just code right click on it and select "View Designer", if you still have trouble try posting a screenshot.

In Visual Studio 2013 when I add an existing form then controls don't appear on designer

I'm working on a windows form application. I start a new project. I delete the Form1 stuff from the new project. I go and add from existing in the solution explorer and choose Form1.cs, Form1.Designer.cs, and Form1.resx from another project. When I look at the designer Form1 just looks blank, like a new one would with none of the controls appearing. The program still compiles fine with all it's controls intact. Did I miss a step somewhere? I've closed and reopened the project etc. This happens every single time repeatedly so I believe I'm missing something but searching here or the rest of the web hasn't provided me a solution. Maybe it's just assumed to be known by everyone already?
I am just learning c# and Visual Studio so hopefully I didn't miss something stupid. I was following direction for how to do this from a book. Some projects are re-used to teach a new idea so they have you start a new project and add in existing items from the original to then work on the new idea.
In VS 2013 I chose "Add existing Item" and just selected the .cs files, don't add *.Designer.cs and *.resx files. Then waited for few minutes and restarted VS2013. Designer.cs and resx files appeared as associated with Forms but they were excluded. I right clicked them and chose "Include In Project". Then it worked fine.
Make sure that you are loading the Form1 that you think you are loading.
By default, Visual Studio 2013 (on Windows 7) will create a folder in Documents (C:\Users*Your user name*\Documents) called "Projects". Whenever you create a new project from within Visual Studio by going to File->New Project, Visual Studio will (by default) create a new folder in the Projects folder with the project name.
I think when you "delete" Form1, you're not actually deleting it, just removing it from the project. When you go to add Form1, you're just selecting it from the same project folder, when you actually wanted to load it from a different project folder.
Try this: In your current project (the one where you deleted Form1 and then added it), in the Solution Explorer, right click on the project, and select "Open Folder in File Explorer".
This will open the project folder on disk. Now, delete Form1.cs from within Visual Studio, and switch back to the project folder. If Form1.cs is still in that project folder, then you just removed it from the project. The actual files still exist on disk. When adding existing items, Visual Studio will typically default to the selected project folder.
I have a very strong suspicion that the Form1 that you are really looking for resides in a different project folder. Without knowing the book or tutorial you are following, I can't give you any hints as to where the Form1 you want is located.

how insert form from project other in visual c#

I have a Project in which there is a form that has several objects (controls) in itself. I want to add this form to another Project in another Solution. How to I can do this. Thanks.
This is a good thing to reuse your code :)
You have to make a library project.
1)File => New Project
2)Check Visual project in the tree
then select "Class Library", give it a name "MyFormLib"
3)Then simply copy paste YourForm.cs and YourForm.designer from your app project, to "MyFormLib".
4)Now go to solution explorer, browse to your application project, right click on "references" then "add reference"
5)To finish click on "solution" then choose your library project "MyFormLib"
.
6)You can now use the form from the library project inside your application project.
e.g : new MyFormLib.TheForm()
7) To reuse your form in your second application, redo steps 4 to 6
Just simply open the project where you want to add the existing form:
Right click on the Solution Explorer
Select "Add" -> "Existing Item..."
Browse your other project's folder, and search for the 3 files of your form:
yourForm1.cs, yourForm1.Designer.cs, yourForm1.resx
The simplest way is to
Open the destination solution in Visual Studio.
On the Solution Explorer, right-click the destination Solution name and Click on Add > Existing Projects. Identify the project with your source Form.
Move the form from source to destination project (The designer and resx files will move with it)
Change relevant namespace specifications and then you may remove the old form.

Duplicate items are not supported by the "Resources" parameter

The item obj\Debug\BookStore.MainForm.resources was specified more than once in the Resources parameter. Duplicate items are not supported by the Resources parameter.
How do I fix this?
This error happened when you copy and paste a form in the 'Solution Explorer' pane. Then you change name of one forms. Visual studio give the same name for both and then, when you rename form, Visual Studio do some refactoring for you and rename Designer class for both forms (not only for new).
You can fix this two ways:
Close Microsoft Visual Studio, then browse to your project folder from external program (ex. Total Commander). Into the folder where both forms are defined you can see your form's .cs and .Designer.cs file. Open the .cs and .Designer.cs files for your form in a text editor. Find and replace every instance of the original form name with new name. And if you rename already rename some resources, check file for original form also (if they are only original form name but not anything for new form name). Then save all files, start Microsoft Visual Studio and rebuild your project.
You can try chcek and rename declaration for each occurance of original form name in new .cs and .Designer.cs files but try disable refactoring. If you already renamed new form, in .Designer.cs for old form you maybe see this:
namespace YourProjectNamespace
{
partial class NewFormName
{ .. }
You must rename NewFormName to OldFormName and when Visual Studio offer you a refactoring menu (small reg rectangle before last letter of renamed object) do not make anything.
This happened to me when I created a partial form class. When I unintentionally viewed it in Design mode it created a localized resx file for the new partial form. I deleted that resx file and that resolved it.
you cant add to the resources file 2 items with the same name/key. it has to be unique
Check the *.resx files in your project as #Royi Namir described.
In case you have already done that: check your .resx.designer files. Some programs "optimize" the designer files.
The designer files are just plain xml. If they are not in sync with the corresponding xml you'll get an exception as described.
I have same problem, and I able to resolve it by these steps:
Right-Click to your form name example: MainForm
To Review: Select Find All References now you will see the list of form of possible conflicts
To Fix: Select Refactor -> Rename -
Select Preview reference changes
Rename it Differently
Un-checked for the Conflict Form/class

How to solve a "duplicate items" error in the "Resources" parameter

While working on my project, I got this error:
The item "..." was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter.
(Removed the item's name, doesn't matter)
However, I do not know how to solve this. Where do I find this parameter in Visual C# Express?
I guess the item "..." is a form, then:
Remove the "..." form from recent solution (and save somewhere)
Recompile the project
Save the solution
Restart the solution
Add the "..." form
Recompile
Create a backup of both the .cs and .designer.cs file which is giving the error and then delete that file from the project. Rebuild the solution and then copy back both .cs and .designer.cs files. Finally, rebuild the solution again.
I received this error after I copy and paste Form1 (for example) in my project.I rename Copy in Form2, but Form2 had next line in *.cs "public partial class Form1". As i understand after copying class name didn't change. I resolved this problem by adding a new form and copying there controls from my old form. The Old form was deleted.
A slightly simpler way ..
Select the form and then right-click and select "Exclude from Project".
Clean and Recompile project
Select the "Show all files" icon on Solution toolbar to show the excluded form files.
Select the form and then right-click and select "Include in Project" to add it back.
Recompile project
Save All to ensure that project file is saved.
No need to restart Solution or move the form.
This happen when you change name form it duplicate resources file of form.
You open old copy all items and paste to new resource then delete old res file.
Rebuild Solutions.
To fix the issue I browsed to [obj > Debug] and [obj > release] and deleted any files which referenced the word resources. After this, my project built successfully.

Categories