Copying winforms between projects in Visual Studio

后端 未结 18 2024
天涯浪人
天涯浪人 2020-12-13 18:16

What is the best way to copy or cut/past a form from one Project to another Project within a Solution in Visual Studio?

Whenever I try it, using the solution explore

相关标签:
18条回答
  • 2020-12-13 18:43

    Make sure that you copy not only the Form.cs, but also the Form.designer.cs and Form.resx files.

    But I need to ask why you would want to maintain a copy of the same form in multiple projects within the same solution. Sounds as if you might want to generalize the code in it, put it in a class library and re-use it in the places where it is applicable.

    0 讨论(0)
  • 2020-12-13 18:47

    It's way easier now in 2012. Just go to File > Add > Existing Project > Drag and drop the form into the project that you want to add it to.

    0 讨论(0)
  • 2020-12-13 18:47

    I tried the following process in Visual Studio 2012 and it worked.

    1. Add the project from which you want to import form to your solution, by right clicking on solution > Add > Existing project menus. Select the project and click OK.
    2. Now right click on the form you want to copy, select copy.
    3. Right click on the project where you want to copy and select paste.
    4. The form will be copied to your project, now rename the namespaces.
    5. Remove the project you added in the step 1 from your solution.
    0 讨论(0)
  • 2020-12-13 18:48

    Use ReSharper (get the demo), right-click the class in Code View, Refactor->Move, and move it to another project.

    The added benefit is that if you change the namespace by moving it between projects, it'll auto-update all references.

    0 讨论(0)
  • 2020-12-13 18:48

    If you need use the same form in differents projects, the solutions is: Create a "Class Library Project", to this proyect you add the forms what you need share, then just add the reference to the dll to your main project, you will can make reference to forms easily. Its works perfect for me

    0 讨论(0)
  • 2020-12-13 18:50

    ** This one works for me:

    1) Copy the source files (.cs or vb, .designer, .resx) into target folder

    2) Show hidden files in target solution

    3) Select these files and include them into project.

    This will add winform or any other partially divided files cleanly.

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