Search code examples
c#formsprojects-and-solutions

c# Calling a form from another project


Got a problem with calling my forms from other projects. I have a solution with 3 projects. Now for example I want to call a form with a buttonClick from project A when I'm on project B.

This is easy since I just put the folder in my solution (with my other projects) then in VS, I just add this project to my solution explorer and then I make a reference from project A to project B. Now i can call forms like this (when in project A):

    projectB.Form1 f1 = new projectB.Form1();
    f1.Show();

But when i try to do the same with project A when I'm in project B

    projectA.Form1 f1 = new projectA.Form1();
    f1.Show();

Then I get an error message saying that projectA doesn't exist etc.

How can I resolve this? Also make a reference to project A from project B ?..

Thanks in advance


Solution

  • In the Solution Explorer, right-click the "References" folder under Project A, then Add Reference, Solution, and select Project B. You can avoid using projectA. everytime by adding the line using projectA; at the top of the file.