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

后端 未结 21 2137
予麋鹿
予麋鹿 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:33

    Here's an approach that doesn't involve closing the project and reopening it:

    1. Add the 3 existing form files (cs, Designer.cs and resx).
    2. Now, exclude the 3 files you just added from the project.
    3. Open the Add existing item explorer window and go to your project directory.
    4. Select the cs file and Add.
    5. Tada. all good
    0 讨论(0)
  • 2020-12-13 09:36

    Maybe it is because of using visual studio 2012, but all these solutions didn't work. AtConway gave a hint to edit the csproj file. And that hint worked.

    1. Open the solution with the project that you want to add your three files.
    2. Let's assume you want to add MyForm.cs / MyForm.Designer.cs and MyForm.resX. Make sure they are in the folder of your project
    3. Add a dummy form (or usercontrol) with a dummy name: MyTempForm.
    4. Save the solution and close it in Developer Studio
    5. In a windows explorer delete the three MyTempForm files
    6. Rename your three MyForm files in MyTempForm, with the same extensions.
    7. Open your solution again in Developer Studio 2012
    8. See that your MyForm is now fully available as MyTempForm
    9. In the solution explorer rename MyTempForm back to MyForm
    0 讨论(0)
  • 2020-12-13 09:36

    Drag and drop .cs files from filesystem to project tree in Solution Explorer (for example):

    • mainForm.cs
    • mainForm.Designer.cs

    Don't forget about references if it is not Windows Forms project.

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

    Although this is an old post, I was having the exact same problem as @MatthewRadford had described above. My workaround for this was to only add the .CS file (do not add the .resx file), and allow visual studio to automatically generate the .resx file right after adding the .cs file.

    However, I found a permanent solution. If you began to experience this problem immediately after upgrading to a new version of visual studio, it is possible that during the upgrade, Active Reports was not registered properly. The solution is to deactivate your Active Reports (using GrapeCity License Manager), uninstall Active Reports, reinstall Active Reports from scratch, and reactivate your license. You should now be able to add the ReportName.cs and ReportName.resx, as well as the Designer.cs file, all at the same time, while having visual studio correctly handle their dependencies.

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

    You can still use "Add Existing iTem"

    1. "Add Existing iTem", select three files (.cs .resx .Designer.cs)

    2. make sure "namespace Application" in your .cs file is the same as the project

    3. now you can use auto-complete the Form you just added.

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

    You need actually 2 files: - Form1.cs - Form1.Designer.cs

    Copy - paste them to your new project (just make sure there is no such form with the same nameexisting in new project)

    0 讨论(0)
提交回复
热议问题