I'm a very newb and know nothing about any IDEs, I've encountered a problem where if I change "Form1" to any other name with proper refactoring it won't add any textBox in the solution explorer, I will see the textbox in the [Design] form but not in the code.
Can someone explain me how to rename things without Visual Studio losing total trace of objects ?
Eventually how can I insert objects manually via code, I know there is a solution but I don't know where find this code to generate an object.
I appreciate any help, not that I've started C# a couple weeks ago.
CodePudding user response:
How you change the name of the form is important.
If you simply open the code file and change it's name in the .cs
file, that's going to fail pretty quickly. A .designer.cs
file sits behind the .cs
file and contains all the controls, and it thinks the name of the form is Form1
.
The best way to rename a form is to either:
Use the Visual Studio shortcut to open the Rename dialog. (For me, the shortcut is
CTRL R R
. For you, it may beF2
.) Use the dialog to type in a new name and pressenter
. This will change the form's name everywhere it appears in the solution.Right-click on the form in Solution Explorer. Select Rename from the menu that appears. Type in the new name for the file and press
enter
. When prompted to rename the type to match the file name, selectYes
. This will also change the form's name everywhere it appears.
CodePudding user response:
For Form name change: Select Form Design Press F4 (Properties of Form) Form's Properties will open Goto Form Name Option Change the Name and press enter Your form name gets changed successfully.
Open Form.Designer.cs for codeing of the designing part.