标识同一表单的实例
本文关键字:实例 表单 标识 | 更新日期: 2023-09-27 18:33:14
我们如何识别同一表单的实例
这是我的问题:我只想显示同一表单的每个实例一次我做了:
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
像这样的事情,问题中没有足够的细节来给出确切的答案:
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具有公共地址属性。