从子窗体关闭父窗体

发布于 2024-12-21 17:12:33 字数 344 浏览 3 评论 0原文

我的表格有问题。我有一个父母和孩子的表格。在儿童形式中,我有一个按钮。我想使用按钮关闭父窗口并创建新的实例父窗体并显示新的父窗体。 有人可以帮助我吗? 我尝试过

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心病无药医 2024-12-28 17:12:33

从子表单调用父函数

Main frm = new Main();
frm.Show();
frm.Activate();
this.Hide();

这将隐藏当前窗体并显示主窗体。

calling parent functions from child form

Main frm = new Main();
frm.Show();
frm.Activate();
this.Hide();

This will hide the current form and shows Main form.

我恋#小黄人 2024-12-28 17:12:33

您可以从子级的父级获取引用,然后使用父级的 close 方法。

You can get a ref from parent in child and then use close method of parent.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文