如何检查是否在Windows窗体已经打开,并关闭它,如果它是什么? [英] How to check if a windows form is already open, and close it if it is?

查看:143
本文介绍了如何检查是否在Windows窗体已经打开,并关闭它,如果它是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格的FM这是打开每10分钟一个简单的信息窗口( fm.Show(); )。

我怎样才能让每10分钟就会检查形式的FM是开放的,如果它是打开它关闭并重新打开它!

现在的形式FM总是与形式FM =新表()创建的; 结果
所以当我尝试检查,如果窗体打开它永远是假的,打开一个新窗口,即使有!前一种形式

我需要有一个工具,给它一个独特的身份,然后检查是否这种形式具有独特的身份开了还是不行!

我不希望只是更新表单(FM)上的数据,因为我有一个按钮的复杂信息。

表单名称为UpdateWindow

解决与以下内容:

 形成FC = Application.OpenForms [UpdateWindow];如果(FC!= NULL)
   fc.Close();fm.Show();


解决方案

这也许可以帮助:

 的FormCollection FC = Application.OpenForms;的foreach(在FC表格FRM)
{
//遍历
}

在foreach一些code检测的具体形式,它可以这样做。虽然未经测试

上找到<一href=\"http://bytes.com/topic/c-sharp/answers/591308-iterating-all-open-forms\">http://bytes.com/topic/c-sharp/answers/591308-iterating-all-open-forms

I have a form "fm" that is a simple info window that opens every 10 mins (fm.Show();).

How I can make that every 10 mins it will check if the form "fm" is open and if it is open it closes it and open it again!

Now the form fm is always created with form fm = new form();
so when I try to check if the form is open it will always be false and open a new window even if there is one form before!

I need to have a tool to give it a unique identity and then check if this form with unique identity is opened or not!

I do not want to just update the data on the form (fm), because I have a complicated info with buttons.

The form name is "UpdateWindow"

Solved with with the following:

Form fc = Application.OpenForms["UpdateWindow"]; 

if (fc != null) 
   fc.Close(); 

fm.Show();

解决方案

maybe this helps:

FormCollection fc = Application.OpenForms;

foreach (Form frm in fc)
{
//iterate through
}

Some code in the foreach to detect the specific form and it could be done. Untested though.

Found on http://bytes.com/topic/c-sharp/answers/591308-iterating-all-open-forms

这篇关于如何检查是否在Windows窗体已经打开,并关闭它,如果它是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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