How do you add an existing form to a new project?

后端 未结 21 2136
予麋鹿
予麋鹿 2020-12-13 09:06

I have never been able to successfully add a Form from an existing file to a new project.

I read on a blog that you add just the *.cs file and the depen

相关标签:
21条回答
  • 2020-12-13 09:38

    The simplest solution that works for me is,

    1. Close visual studio if its open

    2. Copy all the 3 files (.cs, .designer.cs, .resx) into your project folder where all the other forms reside too.

    3. Now open the project using visual studio.

    4. Build the project

    5. Open the form by right clicking it and selecting view designer, this will generate the proper designer.cs for the form. If you don't do this sometimes it might give an error saying

    InitializeComponent doesnt exist int the current context.

    1. Now you may open and edit the .cs code file

    The new form will appear like a normal form in the solution explorer here after.

    0 讨论(0)
  • 2020-12-13 09:41

    Go to solution explorer and right click on it then add existing item, here select the existing form path. Now, and this is important, on the page where you want to use existing form, you must add header file:

    using "your existing project name";
    
    0 讨论(0)
  • 2020-12-13 09:42

    All that is needed in visual Studio 2012 is the following:

    1. Copy the three files for the form into the project folder (.cs, .designer.cs and .resx)
    2. Go to the project and add an existing object.
    3. Select the .CS file
    4. It will import and look like a standard code file. Double-clicking on it will not open the designer as mentioned above. However just click on save all files and then close and re-open the project, now it is recognized as a form and works correctly.
    0 讨论(0)
提交回复
热议问题