skip to Main Content

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.

enter image description here

I appreciate any help, not that I’ve started C# a couple weeks ago.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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:

    1. Use the Visual Studio shortcut to open the Rename dialog. (For me, the shortcut is CTRL+R+R. For you, it may be F2.) Use the dialog to type in a new name and press enter. This will change the form’s name everywhere it appears in the solution.

    2. 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, select Yes. This will also change the form’s name everywhere it appears.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search