Copying winforms between projects in Visual Studio

后端 未结 18 2023
天涯浪人
天涯浪人 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:35

    If you want to forms in same machine then simply you can do this.

    In Solution Explorer Project --> Add --> Add Existing Item.

    Select only .cs (Sample.cs) file from source directory and Refresh the current solution Explorer it will Work.

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

    For Visual Studio V.12 this is the only method which worked for me (It is a mix of above entries):

    • Copy through Files Explorer the three files that the form is made up.
    • At the top bar of the solution explorer in Visual Studio, turn on "show all files" .
    • The file.cs file appears in grey. Click right-button and select: "Include in Project". The solution explorer automatically links the three file (.designer and .resx under .cs file). The file.cs change icon to from c++ to form icon.
    0 讨论(0)
  • 2020-12-13 18:37

    I have tried the below steps and its worked fine.

    1. copy all the 3 files and icon files (if any) to the target project.
    2. Now go to your project solution explorer and click the show all files icon in the top of the sol.explorer
    3. now you can see your newly added files showing in your project.
    0 讨论(0)
  • 2020-12-13 18:38

    I am using Visual Studio 2010, below are the steps I performed:

    1. Copy all 3 files (.cs, .resx, .Designer.cs) into destination project folder.
    2. At Visual Studio, right click Project -> Add -> Existing Item...
    3. Select all 3 files (.cs, .resx, .Designer.cs), click Add.
    4. Change the namespace on 2 files (.cs, .Designer.cs), if it is different namespace on destination project.
    5. Run the project.
    6. Done!
    0 讨论(0)
  • 2020-12-13 18:39

    I finally figured out as followings:

    1) copy 3 files of your wished form whose file extension are .cs, .resx, .Designer.cs.
    2) Add Existing and select formName.cs.
    3) check the namespace and Name property value of the added form.
    4) In Program.cs file, use using NameSpace; and replace new NameSpace.formName() in the line of Application.Run().

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

    Figured it out - knew it would be something daft.

    Apparently the target project should have the references:

    • System.Windows.Forms
    • System.Drawing

    included within the project FIRST before you do any copy or pasting or else you will get the problem I described.

    Thanks for anyone who tried to help BTW.

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