Copying winforms between projects in Visual Studio

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

    Using VS2013 just tested this and it appears reliable and consistent. This is similar to some comments above but adds another method that's quicker.

    (1st) In Windows File Explorer highlight and copy all 3 Form files (.vb or .cs, .designer, .resx)

    (2nd) This can be accomplished 2 ways:

    (2a-1) In File Explorer paste the 3 files into the project folder with your other forms

    (2a-2) In VS Solution Explorer, turn 'Show All Files' on, Right Click on the pasted form & 'Include in Project'. It should work without other changes.

    Or, I think better:

    (2b-1) In VS, click into Solution Explorer and paste w/Control-C. (For some reason the right-click context menu in Solution Explorer may not show a paste option, but it works from the keyboard.) This method adds the form to the project directly without having to 'Include in Project' as above. With this method you can add as many forms at a time as you like (all 3 files for each) in a single step.

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

    If you are using VS 2015, then you just want to add ".vb" file and change the name space with new project name.

    Ex: If you want to add "Form1" that created using VS2008 to new project that created using VS2015.

    1. Copy all ".vb" file, ".resx" file, ".disigner.vb" file to the new project folder.
    2. Then change the name space of ".disigner.vb" file using new project name.

    These two steps worked for me.

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

    In visual Studio 2015, click on solution explorer and right click on mouse Add->Existing Item and select from another project which form you want to add like Form.cs and automatically Form.designer.cs , Form.resx will be added

    0 讨论(0)
  • 2020-12-13 18:31
    1. Copy the three files, .cs, .designer, resx to the target solution folder.
    2. In the target project, select Add existing item and add the designer file first.
    3. Modify the Namespace attribute. The .cs file should come in as well.
    4. Modify the namespace in the .cs file.
    5. Add the resx file using Add existing item.
    0 讨论(0)
  • 2020-12-13 18:31

    To copy a form from one VS2013 project to another, the easiest, (fewest mouse clicks) is:

    1. In your target project, right mouse click on your parent folder (likely your project) and in the menu select, "Add; Existing Item".

    2. Then select the form's cs file in your source project. For example select Form.cs (not the Form.Designer.cs or Form.resx).

    3. Open Form.cs in your target project and change the namespace (all instances).

    4. Close and reopen Form.cs and you will see all the controls, etc.

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

    Are you selecting the file, or using the designer to "Copy" all of the controls? Selecting the YourForm.cs file in the Solution Explorer and copying it via copy-and-paste or drag-and-drop to your other project should accomplish what you need.

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