如何在MDI表单中关闭子表单 [英] How to close child form in MDI form

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

问题描述

我想在c#.net中关闭所有以MDI格式打开的子窗体,任何人都可以帮忙

I would like to close all opened child forms in MDI form in c#.net can anyone help

推荐答案

看MSDN文档页面是如此困难吗?在一个类上找到方法Close?

问题是:为什么要使用MDI?人们将要花多长时间?谁需要MDI?为什么要折磨自己并吓users用户?
帮自己一个忙:完全不要使用MDI.没有设计,您可以更轻松地实现设计,并且质量更高.即使Microsoft也不鼓励使用MDI,实际上,Microsoft已将其从WPF中删除,并且几乎不支持它.更重要的是,如果您使用MDI,则会吓跑所有用户.只是不要.我可以解释该怎么办.

请参阅:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [在WPF中使用MDI窗口的问题 [ ^ ],
MDIContainer提供错误 [如何在WPF中创建MDI父窗口? [ ^ ].

—SA
Is it so difficult to look at the MSDN documentation page on a class and find the method Close?

The problem is: why MDI? How much longer people are going to get into it? Who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don''t. I can explain what to do instead.

Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to Create MDI Parent Window in WPF?[^].

—SA


// Assume that your parent window is parentForm
// When you are creating each form, add it to parentForm's owned forms
// Let's say you're creating form1
MyForm form1 = new MyForm();
parentForm.AddOwnedForm(form1);//if you're in your parentForm's class use this.AddOwnedForm(form1);
form1.Show();

// then when you want to close all of them simple call the below code

foreach(Form form in parentForm.OwnedForms)
{
      form.Close();
}

// And also you can call this if you're in parentForm's class
foreach(Form form in this.OwnedForms)
{
      form.Close();
}</pre>


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

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