检查表单是否已打开C# [英] Check if form is already opened C#

查看:59
本文介绍了检查表单是否已打开C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我有一个包含3个组合框的表单,根据父项和一个按钮填充其他项目。

点击事件另一个表单根据组合框中的选定项目打开。

我想检查表单是否已经打开,而不是从同一个选项中打开另一个表单。

I have one form with 3 comboboxes that populate eachother items based on the parent one and a button.
On click event another form opens based on selected item from the combobox.
I would like to check whether the form is already opened and not open another from the same selected item.

我这样做了

var sensor = new Sensor();
            sensor = comboBoxSensor.SelectedItem as Sensor;

            if (sensor.SensorType == "Fire")
            {
                fireSensorId = sensor;
                var fire = FireSensor.GetInstance();
                fire.Show();
            }

GetInstance()方法确保一次只打开同一项的1种形式。

the GetInstance() method ensures that only 1 form of same item is opened at a time.

public static FireSensor GetInstance()
        {
            if (instance == null)
            {
                instance = new FireSensor();
            }
            else
            {
                instance.BringToFront();
            }
            return instance;
        }

然而,此当前支票 - "火"可能存在于不同的场景中(不同的父组合框选择)



这就是为什么我想根据组合框valueMember进行第二次检查,这将是传感器ID。

However this current check - "Fire" could exist in different scenarios (different parent combobox selection)

That's why I want to do 2nd check based on the combobox valueMember which would be the sensor ID.

所以我想让几个"Fire"实例成为可能。只有他们有不同的ID。如果不是我不想打开更多。我有点被困在这里,任何建议或帮助表示赞赏。谢谢!

So I want to make it possible to have several instances of "Fire" only if they have different ID. If not I don't want to open more. I am kind of stuck here, any suggestions or help is appreciated. Thank you!

推荐答案

我首先要完成方法中的所有工作。类似于:

I would start by doing all of the work in the method. Something like:

            if (sensor.SensorType == "Fire") { NewGetInstance(); }


这篇关于检查表单是否已打开C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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