0

我们如何识别相同表单的实例

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

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
4

1 回答 1

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 具有公共地址属性。

于 2012-05-05T20:11:02.777 回答