识别相同表单的实例

时间:2012-05-04 10:02:15

标签: c# winforms

我们如何识别同一表格的实例

这是我的问题: 我想只显示一次相同表单的每个实例 我做了:

for (int l = 0; l < 2; l++)
        {
            cameraInstance[l].Start();
            if (cameraInstance[l].MoveDetection == true)
            {
                Formes.CameraViewVS f1 = new Formes.CameraViewVS(cameraInstance[l], adresseIPArray[l]);

                foreach (Form S in Application.OpenForms)
                {
                    if ((S.GetType() == typeof(Formes.CameraViewVS)) && (cameraInstance[l].adresse == f1.IP))  
                    {
                        S.Show();
                        cameraInstance[l].MoveDetection = false;
                        return;
                    }
                }

                                   f1.Owner = this;
                f1.Show();

            }             
        }
Any idea

1 个答案:

答案 0 :(得分:1)

像这样的东西,问题中没有足够的细节来确切答案:

            foreach (Form S in Application.OpenForms)
            {
                var frm = S as Formes.CameraViewVS;
                if (frm != null && frm.Addresse == cameraInstance[l].adresse) {
                    // Match, activate it
                    cameraInstance[l].MoveDetection = false;
                    frm.WindowState = FormWindowState.Normal;
                    frm.Activate();
                    return;
                }
            }
            // No match found, create a new one
            var f1 = new Formes.CameraViewVS(cameraInstance[l], adresseIPArray[l]);
            f1.Show(this);

假设CamerViewVS具有公共Addresse属性。