要检查MDI子项是否存在,请使用c#
我有MDI应用程序,并在焦点/选择上操作新表单。为了避免多次打开同一个图像,我编写了这段代码,但它有一个问题 私有void lstview1_MouseDoubleClick(对象发送方,MouseEventArgs e) {要检查MDI子项是否存在,请使用c#,c#,C#,我有MDI应用程序,并在焦点/选择上操作新表单。为了避免多次打开同一个图像,我编写了这段代码,但它有一个问题 私有void lstview1_MouseDoubleClick(对象发送方,MouseEventArgs e) { 字符串窗口_name=this.lstview1.FocusedItem.Tag.ToString() } 其中,childform标记再次是int.parse(窗口名称)。 但它抛出的错误使[this.mdichilds[index].Tag]首先需要存在。 我怎样才能
字符串窗口_name=this.lstview1.FocusedItem.Tag.ToString() } 其中,childform标记再次是int.parse(窗口名称)。 但它抛出的错误使[this.mdichilds[index].Tag]首先需要存在。
我怎样才能检查这种存在/或者怎样才能使我的代码更好。这种方法怎么样:
private void ShowForm(string name)
{
Form targetForm = null;
foreach (Form frm in Application.OpenForms)
{
if (frm.Tag != null)
{
if (frm.Tag.ToString() == name)
{
targetForm = frm;
break;
}
}
}
if (targetForm != null)
{
targetForm.Activate();
}
else
{
// create new form and show it
}
}
private void ShowForm(string name)
{
Form targetForm = null;
foreach (Form frm in Application.OpenForms)
{
if (frm.Tag != null)
{
if (frm.Tag.ToString() == name)
{
targetForm = frm;
break;
}
}
}
if (targetForm != null)
{
targetForm.Activate();
}
else
{
// create new form and show it
}
}