[英]C# Open a form from another form, which is located in a different project
I have two different projects, DriverSide
and LogInForm
.我有两个不同的项目,
DriverSide
和LogInForm
。 In both of them is a form, in DriverSide
the form Form1
will be executed on the start of the application and in LogInForm
the important form is the UserOnTrip
form.它们都是一个表单,在
DriverSide
,表单Form1
将在应用程序启动时执行,而在LogInForm
,重要的表单是UserOnTrip
表单。 On Form1
is a button and with it´s click event i want to open the UserOnTrip
form, but i dont know how to handle it because the forms are on different projects.在
Form1
是一个按钮,通过它的点击事件我想打开UserOnTrip
表单,但我不知道如何处理它,因为这些表单位于不同的项目中。
This is my button click method:这是我的按钮单击方法:
private void _btnAccept_Click(object sender, EventArgs e)
{
LogInForm._pnlUserOntrip _pnl = new LogInForm._pnlUserOntrip();
_pnl.Show();
//System.Diagnostics.Process.Start(Application.StartupPath.ToString() + @"\_pnlUserOnTrip.exe");
LogInForm.LoadingScreen _load = new LogInForm.LoadingScreen();
_load.Hide();
}
}
And this is the layout of my solution explorer:这是我的解决方案资源管理器的布局:
Go to your solution explorer and right click on the project you want to execute.转到您的解决方案资源管理器并右键单击您要执行的项目。 Now click 'Set as start project'.
现在单击“设置为启动项目”。 This project gets highlighted then a bit, you should see atleast any difference.
这个项目被突出显示了一点,你至少应该看到任何不同。
Have a look at this picture . 看看这张照片。 There are the two different projects: John.Socialclub.Data and John.Socialclub.Desktop.
有两个不同的项目:John.Socialclub.Data 和 John.Socialclub.Desktop。 And you dont click on any of those files below, right click on of your projects itself and set them simply as start project.
并且您不要单击下面的任何这些文件,右键单击您的项目本身并将它们简单地设置为启动项目。
Updated:更新:
So i understood it that way, that you execute in the project DriverSide
the Form1
.所以我是这样理解的,你在项目
DriverSide
执行Form1
。 On this form you have a button which shell open the form UserOnTrip
which is located in the LogInForm
project.在这个表格你有一个按钮,打开外壳的形式
UserOnTrip
其位于LogInForm
项目。
First of all you want to add a reference to the DriverSide
project.首先,您要添加对
DriverSide
项目的引用。 Go once again to the solution explorer and righ click on References
.再次转到解决方案资源管理器并右键单击
References
。 Then click Add reference
.然后单击
Add reference
。 Then a menu pops up where you select on the left side projects
.然后会弹出一个菜单,您可以在左侧的
projects
选择。 Now there should be your project LogInForm
listed, you select it with the comboBox and press OK.现在应该列出了您的项目
LogInForm
,您可以使用组合框选择它并按 OK。
Now we are in the Form1
of DriverSide
:现在我们在
DriverSide
的Form1
中:
In the beginning note that you have to add this using
reference to use the reference to the LogInForm
.在开始时请注意,您必须添加 this
using
reference 才能使用对LogInForm
的引用。 Add this to the other using references.使用引用将其添加到另一个。
using LogInForm;
namespace DriverSide
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void _btnAccept_Click(object sender, EventArgs e)
{
UserOnTrip testWindow = new UserOnTrip();
testWindow.Show();
}
}
}
I just copied your button click method _btnAccept_Click
.我刚刚复制了您的按钮单击方法
_btnAccept_Click
。 Insert this code and you should be fine.插入此代码,您应该没问题。 You can ignore the constructor
public Form1()
, i just placed it in there that you feel familiar with your code and understand exactly where to place what.你可以忽略构造函数
public Form1()
,我只是把它放在那里,你觉得你熟悉你的代码并确切地知道在哪里放置什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.