首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

父窗体怎么关闭子窗体

2012-06-14 
父窗体如何关闭子窗体父窗体Afrm,子窗体Bfrm问题1父窗体有一个按钮button,如何关闭子窗体。问题2有没有办法

父窗体如何关闭子窗体
父窗体Afrm,子窗体Bfrm
问题1
父窗体有一个按钮button,如何关闭子窗体。
问题2
有没有办法让子窗体在打开30秒后自动关闭或触发一个事件。

[解决办法]
创建子窗体时,保留子窗体实例,直接frm.close
30秒自动关闭,就在子窗体上放个timer,计时30秒
[解决办法]
问题1:

C# code
// 设置父窗体为Mdi容器this.IsMdiContainer = true;// 创建子窗体实例ChildForm frm = new ChildForm ();// 设置子窗体的Mdi父窗体对象frm.MdiParent = this;// 打开子窗体frm.Show();//关闭子窗体this.MdiChildren[0].Close();
[解决办法]
问题2:

C# code
private void timer_Tick(object sender, EventArgs e)        {            this.Close();        }      //         private void Form_Load(object sender, EventArgs e)        {            Timer timer = new Timer();            timer.Interval = 30000;            timer.Tick += new EventHandler(timer_Tick);        } 

热点排行