Pedro Ganesh
Pedro Ganesh

Reputation: 77

Merging forms in different projects

I have two different forms as two different projects. I want to have these two forms in the same project so I can have form 1 appear when user clicks on a button in form 2. How can I include one form into another in VS express?

Upvotes: 0

Views: 1191

Answers (2)

Kevin DiTraglia
Kevin DiTraglia

Reputation: 26078

You can simply add a reference to the second project in the first, add a using statement pointing to that form within the assembly, and upon button click instantiate and show that form.

If you are hell bent on making them in the same project, it should be as easy as just copy pasting that form from one project to another, you may want to change the namespace to match, but you don't have to, again you'll just need to add a using statement to be able to access that form within the other (and make sure it is declared public, you can get away with internal if they are in the same namespace).

Upvotes: 2

Philip Gullick
Philip Gullick

Reputation: 995

First of all, why do you want to move the form?

To use the form in another project simply:

  1. In the source explorer, where references is in the form1 project right click > add new reference > projects > select project from form2
  2. Create a using statement at the top of your code e.g. using projectname;
  3. Ensure the form2 is a public class

To move the form into another project, simply copy the Form2 into the same project as the other. It is usually best practice to have all forms within the same project, especially if they are connected, however sometimes this is not necessarily the case. So do whatever you feel comfortable with.

Of course you should note that the forms cannot have the same name as each other i.e. form1 and form1, and they should be renamed to what they are suited for to avoid confusion in the future. Please do not take your time on this though, it should be quick and easy to identify.

Upvotes: 0

Related Questions