[英]How do I make buttons in two separate C# forms in two separate projects open each other?
I am working with two C# projects in one Microsoft Visual Studios solution.我正在一个 Microsoft Visual Studios 解决方案中处理两个 C# 项目。 One project contains a form used to select which form from the other project to open.
一个项目包含一个表单,用于从另一个项目中选择要打开的表单。 I also have a 'Back' button on each of my Project 2 forms, which I hope to use to reopen the form selector from the first project.
我的每个 Project 2 表单上还有一个“返回”按钮,我希望用它来重新打开第一个项目中的表单选择器。 I have researched how to get around circular reference dependencies with no luck.
我研究了如何在没有运气的情况下绕过循环引用依赖项。 I would prefer to keep these as two separate projects.
我更愿意将它们作为两个独立的项目。 Will I need to consolidate everything into one messy project, or is there a way to accomplish what I'm trying to do?
我是否需要将所有内容整合到一个凌乱的项目中,或者有没有办法完成我想要做的事情? Thank you in advance.
先感谢您。
EDIT:编辑:
I found a simple, but effective solution.我找到了一个简单但有效的解决方案。 I only need to reference Project 2 from Project 1, because I can pass through the Project 1 form as a parameter into the Project 2 forms, then display the first form whenever a button is clicked.
我只需要从项目 1 中引用项目 2,因为我可以将项目 1 表单作为参数传递到项目 2 表单中,然后在单击按钮时显示第一个表单。 Thank you again.
再次感谢你。
Follow these steps:按着这些次序:
In Program.cs add the following code:在 Program.cs 中添加以下代码:
private static void OpenForm(String formName) { if (formName == "Form1") // Open your Form1 else // Open second Form2 } private static void OpenForm(String formName) { if (formName == "Form1") // 打开你的 Form1 else // 打开第二个 Form2 }
Now you can just open the forms on the button click event click by:现在您可以通过以下方式打开按钮单击事件上的表单:
Process.Start("Opener.exe Form1"); Process.Start("Opener.exe Form1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.