简体   繁体   English

如何让两个独立项目中的两个独立 C# 表单中的按钮相互打开?

[英]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:按着这些次序:

  1. Create a New Project (say 'Opener') in the same solution as a simple command utility.在与简单命令实用程序相同的解决方案中创建一个新项目(比如“Opener”)。
  2. Add the reference to the main projects to Opener.将主要项目的引用添加到 Opener。
  3. 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 }

  4. 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.

相关问题 C#:从单独的表单中关闭和打开两个表单 - C#: Close and Open two forms from a separate form C# - 如何使两个表单相互引用 - C# - How to make two forms reference each other 如何在 C# 中将字符串拆分为两个单独的变量 - How do I Split the string into two separate variables in C# 如何在绑定到同一数据源的单独表单上获得两个控件以相互更新? - How can I get two controls on separate forms bound to the same datasource to update each other? 如何使两个单独的图片框中的两个 gif 可以相互重叠? - How to make it so two gifs in two separate pictureboxes can overlap each other? C# MouseButtonEventArgs ClickCount - 如何区分单击一次或两次发生的情况? - C# MouseButtonEventArgs ClickCount - How do I separate what happens in one or two clicks? 两个单独的 C# .Net 应用程序在同一台计算机上相互通信的最简单方法是什么 - What is the easiest way for two separate C# .Net apps to talk to each other on the same computer 如何为两个分组的单选按钮使用两个单独的 bool 属性? - How do I use two separate bool properties for two grouped radio buttons? 我如何使两个按钮彼此相邻 - How do I get two buttons next to each other 如何有两个来自不同项目的Window窗体互相显示和隐藏? - How can I have two Window forms, from different projects, show and hide each other?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM