开发者

Best way of calling code from different projects in a C# solution

开发者 https://www.devze.com 2022-12-20 07:25 出处:网络
I have a solution with multiple projects. Both the projects have Forms. Example MySolution ____________________ Project1 (Windows Form)

I have a solution with multiple projects. Both the projects have Forms.

Example

MySolution

|____________________ Project1 (Windows Form)

|____________________ Project2 (Also a Windows Form)

Now I want to call the Form in Project2 from the Form in Project1. Sort of going like this

using (Form2 f2 = new Form2(myFile))
{
 //....
}

Moving Form2 in开发者_如何转开发to Project1 is not an option unfortunately.

What's the best way to go about it.

Thanks


Reference Project2 in Project1, See MSDN - Project References


You need to reference the compiled Project2 dll or exe from Project1. Make sure Form2 is public, so Project 1 can see it. After that, you can create an instance of Form2 in Project1.


You will need to add a reference from Project1 to Project2. This can be done by right-clicking on the project in the solution explorer and selecting "Add Reference". Once the window appears (it will take a moment), click on the projects tab and select the other project. Cyclic references are not allowed so Project1 can reference Project2 or vice-versa, but they can't both reference each other.

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消