Copying winforms between projects in Visual Studio

2019-01-23 11:58发布

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 explorer (drag and drop or right clicking cut and past), it only copies the underlying C# code and not the necessary 'bits and pieces' that help you visualise the form via the form designer.

14条回答
一夜七次
2楼-- · 2019-01-23 12:23

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.

查看更多
成全新的幸福
3楼-- · 2019-01-23 12:23

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.
查看更多
登录 后发表回答