打开另一个表单时如何关闭子表单 [英] How to close child form when another form opend
本文介绍了打开另一个表单时如何关闭子表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我想在另一个子表单时关闭该子表单,请给我相应的代码,
我想问客户关闭当前表格不是吗?如果他单击确定",则表格应关闭.
USIND MDIPARENT
我总共有10个子窗体,如果一个打开的窗体又要关闭.
Hi
I want to close the child form when another child form please give me the code for that,
and i want to ask the customer to close the current form are not ? if he clicks on okay the form should close.
USIND MDIPARENT
I have totally 10 child forms, if one form opened another should close.
推荐答案
在您的父窗体中,处理子窗体FormClosing事件.触发时,您可以询问用户,并使用secondChildFormInstance.Close()
方法关闭第二个子窗体.
In your parent form, handle the Child form FormClosing Event. When it fires, you can ask the user, and close the second child form if you need to - with the secondChildFormInstance.Close()
method.
一种方法是关闭并打开该子项来自MDIParent.当要打开新表单时,可以检查 Form.MdiChildren属性 [ ^ ]中是否有子项,并在必要时将其关闭.
One way to do this is that you close and open the child forms from the MDIParent. When a new form is going to be opened you can check Form.MdiChildren Property [^] if there are any children and close them if necessary.
也许这段代码将对您有所帮助
May be this code will help you
//Get all child forms in MDI container
Form[] ChildFormArray = this.MdiParent.MdiChildren;
// Loop through all child form.
for (int iCount = 0; iCount < ChildFormArray.Count(); iCount++)
{
if( MessageBox.Show("Do you want to close this form " +ChildFormArray[iCount].Text, "", MessageBoxButtons.YesNo )==DialogResult.Yes)
{
//Close child form
ChildFormArray[iCount].Close();
}
}
这篇关于打开另一个表单时如何关闭子表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文