从子窗体关闭父窗体
我的表格有问题。我有一个父母和孩子的表格。在儿童形式中,我有一个按钮。我想使用按钮关闭父窗口并创建新的实例父窗体并显示新的父窗体。 有人可以帮助我吗? 我尝试过
private Form1 m_parent;
public Form2(Form1 frm1)
{
InitializeComponent();
m_parent = frm1;
}
并且 之后 m_parent.Close() ,但我得到的只是两个表单都关闭了,就是这样。在 m_parent 之后,我创建了新实例,但我的应用程序已关闭。
I have a problem with my forms. I have a parent and child form. In child form I have a button. I want to close parent window using button and create new instance parent form and shows new parent form.
Anyone can help me?
I tried
private Form1 m_parent;
public Form2(Form1 frm1)
{
InitializeComponent();
m_parent = frm1;
}
and
after that m_parent.Close(), but only what I got is both forms was closed and this is it. After m_parent i create new instance but my application was closed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从子表单调用父函数
这将隐藏当前窗体并显示主窗体。
calling parent functions from child form
This will hide the current form and shows Main form.
您可以从子级的父级获取引用,然后使用父级的 close 方法。
You can get a ref from parent in child and then use close method of parent.