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

后端 未结 21 2157
予麋鹿
予麋鹿 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条回答
  •  Happy的楠姐
    2020-12-13 09:27

    You can import an existing Form into a project. The files that need to be imported depend on the version of the Visual Studio used to create the form.

    I will assume that you have two separate projects, Foo and Bar, in different solutions:

    C:\
        Projects\
            Foo\
                Foo.sln
                Foo.vcproj
                Program.cs
                Foo.cs
                Foo.Designer.cs
                Foo.Designer.resx
    

    and

    C:\
        Projects\
            Bar\
                Bar.sln
                Bar.vcproj
                Program.cs
                Bar.cs
                Bar.Designer.cs
                Bar.Designer.resx
    

    Now, say that you need to import fhe form Foo to the project Bar. First, you need to copy all files that accompany Foo into the Bar project folder:

    C:\
        Projects\
            Bar\
                Bar.sln
                Bar.vcproj
                Program.cs
                Bar.cs
                Bar.Designer.cs
                Bar.Designer.resx
                Foo.cs
                Foo.Designer.cs
                Foo.Designer.resx
    

    Then, open Bar.sln in Visual Studio and right-click on the Bar project in Solution Explorer. Select [Add existing item] and select all files that you copied for the Foo form in the dialog opened. After confirming, you should see the newly imported form correctly in Solution Explorer.

提交回复
热议问题