C#-WinForm - 如何在孩子关闭时关闭父表格? [英] C#-WinForm - How to close parent form when child is closed?

查看:80
本文介绍了C#-WinForm - 如何在孩子关闭时关闭父表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



这是我的问题:



- 我有3种形式:< br $>
表格fParent

表格fChild

表格OpenForm



我想要的当我单击Form fChild上的一个按钮,它会显示Form OpenForm并隐藏Form fParent和Form fChild。

我该怎么做?请帮我。

谢谢和最好的问候!

Hi all!

This is my issue :

- I have 3 forms :
Form fParent
Form fChild
Form OpenForm

I want that When I click a button on Form fChild, it shows Form OpenForm and hide Form fParentand Form fChild.
How can I do that? Please help me.
Thanks and best regards!

推荐答案

主表格



Main Form

namespace cp5
{
    public delegate void dHide(bool hide);
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        void Button1Click(object sender, EventArgs e)
        {
            Form1 fm1=new Form1();
            fm1.delfunc+=hideform;
            fm1.Show();
        }
        void hideform(bool hide)
        {
            if (hide) this.Hide();
            else this.Show();
        }
    }
}







和子表单到隐藏/显示主窗体:






and child form to hide/show main form:

namespace cp5
{
	public partial class Form1 : Form
	{
		public dHide delfunc=null;
		public Form1()
		{
			InitializeComponent();
		}
		void Button1Click(object sender, EventArgs e)
		{
			delfunc(true);
		}
		void Button2Click(object sender, EventArgs e)
		{
			delfunc(false);	
		}		
	}
}


这篇关于C#-WinForm - 如何在孩子关闭时关闭父表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆