在MDI父表单中关闭子表单 [英] closing child form in MDI parent form

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

问题描述

你好,

我有一个MDI父表单,并且在其中有一个用于打开子表单的菜单栏.
当我打开子窗体时,它将在MDI父窗体中打开.
当我打开第二个子窗体时,前一个未关闭.

当我打开新的子窗体时,应该关闭打开的子窗体.....

我该怎么做到...

请帮助...

hello,

i have a MDI parent form and inside that i have menu bar for opening child forms.
when i open a child form it opens inside MDI parent form.
and when i open second child form the previous one is not closing.

the opened child form should be closed when i open new child form.....

how can i achieve this...

please help......

推荐答案

您必须为此编写代码.

使用this.HasChildren检查MDI是否具有子窗体,并使用childForm.Close()关闭该窗体的实例.
You have to write code for that.

Check whether MDI has child form or not using this.HasChildren and close that instance of form using childForm.Close().


打开窗体时,请使用from1.ShowDialog()代替form1.Show().因此,这将不允许您在不关闭当前对象的情况下打开其他对象.
When opening a form use from1.ShowDialog() instead of form1.Show(). So, this will not allow you to open other without closing the current from.


我想您希望一次只能打开特定子窗体的一个实例. > 为此,您需要检查该子窗体的实例是否为null,然后仅打开新实例,否则,如果已经创建了实例,只需将该实例放在最前面即可.
i guess you wanted that only one instance of a particular child form should be open at a time.
For this, you need to check if the instance of that child form is null then only open new instance OR otherwise if instance is already created just bring to front that instance.


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

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