MDI应用问题 [英] mdi application problem

查看:95
本文介绍了MDI应用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建MDI应用程序
因为我有一些孩子形式

我的缺点是:

我使用menuStrip打开子窗体
当我打开第一个子窗体(可能是任何窗体)时
之后,当我打开另一个子窗体时,应该自动关闭我打开的第一个子窗体.

I am creating mdi application
in that i have some child form

my broblem is :

I open child form using menuStrip
when i open first child form(may be any form)
afterthat when i open another child form, first child form i had opened should be automatically closed.

推荐答案

为此,您需要做两件事:
1)在您的MDI父类中保留打开每种表单类型的实例的引用.我可能会将其作为实际形式的一个实例:
To do this, you need to do two things:
1) Keep a reference in your MDI parent class of what instances of each form type are open. I would probably make it an instance of the actual form:
private MyMDIChild current = null;
...
if (current != null)
   {
   current.Close();
   }
current = new MyMDIChild();
current.Show();


2)在显示子窗体FormClosing事件之前,将一个处理程序附加到该子窗体的FormClosing事件上,并在处理程序中将"current"返回为null.


2) Attach a handler to the child forms FormClosing event before you show it, and return "current" to null in the handler.


这篇关于MDI应用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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