如果其实例正在运行,请关闭Windows窗体 [英] Close the windows form if its instance is running
问题描述
如果实例正在运行,请关闭Windows窗体.
我有三种形式
1)普通Windows窗体(命名为主屏幕)
2)MDI表格(名为POS)
3)MDI表格(命名股票)
当我单击[主屏幕]上的按钮时
我通过按钮单击事件从[Main Screen]
打开MDIPOS FORM
.代码是:
Close the windows form if its instance is running.
I have three forms
1) Normal Windows Forms (Named Main Screen)
2) MDI form (Named POS)
3) MDI form (Named Stock)
When I click Button on [Main Screen]
I am opening a MDIPOS FORM
from [Main Screen]
by button click event. The code is:
MDIPOS pos=new MDIPOS();
pos.MdiParent = this;
pos.Activate();
pos.Show();
在关闭表单时遇到问题.
当我关闭MDI Form
或Main Screen Form
其中一个实例仍在运行.
我用过:
Getting Problem in Closing the form.
When I close the MDI Form
or Main Screen Form
one its instance remain running.
I used :
frmMain.Dispose(); //or
frmMain.Close();
然后它的实例仍保持运行.
如果我仅使用一种形式,则它会完美关闭.
如何关闭另一个表单的实例.
因为要访问表单,我们需要创建该表单的新对象,并且销毁了该新对象,但是打开的上一个对象又如何呢?
希望我能很好地解释这个问题.
感谢您的最佳答复
谢谢您
Then also it instance remain running.
If I use only one form, it closes perfectly.
How to close the instance of another form.
because, to access a form, we need to create a new object of that form and that that new object is destroyed , but what about the previous one which was opened.
I hope I explain the problem nicely.
Appreciate your best reply
Thanking You
推荐答案
尝试一下,
在关闭按钮(或)关闭表单事件中使用它
Try it,
use this in your Close Button (or) Form Closing Event
foreach(Form f in this.MdiChildren)
{
f.Close();
}
这篇关于如果其实例正在运行,请关闭Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!