如何关闭子表单中的父表单 [英] How to close parent form in child form

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

问题描述


我是.Net的新手,所以我面临这么多麻烦一段时间是一个,我有2个表单(Form1和form2),当我点击时,form1包含一个按钮第二个表单的按钮应该打开,form1需要关闭。请帮助我....

Hi I am a newbie in .Net so i am facing so much trouble some time here is one ,I have 2 form(Form1 & form2) and the form1 contain a button on it when i will click on the button the second form should be open and the form1 need to be closed .plea help me....

推荐答案

你可以隐藏Form1,因为你无法关闭因为Form1是父表单,除非子表单关闭否则它不能关闭
You can just hide Form1 where as you cannot close it because Form1 is parent form and it cannot be closed unless child form is closed


您好b $ b

在按钮的Click事件中使用此代码



Hi
In the Click event of the button use this code

Form2 test = new Form2();
test.Show();
this.Hide();





使用这个你可以显示form2,form1将会消失。



Using this you can show form2 and the form1 will disappear.


//在父窗体中创建子窗体

Form2 f = new Form2();

f.show(this);

this.Hide(); //隐藏父表格





///结束儿童表格活动

private void Form2_FormClosed( object sender,FormClosedEventArgs e)

{

this.Owner.Dispose(); //关闭父表格

}
//creating the child form in Parent Form
Form2 f=new Form2();
f.show(this);
this.Hide(); //hiding the parent form


///closing Event in child form
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
this.Owner.Dispose(); //closing parent form
}


这篇关于如何关闭子表单中的父表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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