Type ft = null; if (listBox选择A) { ft = typeof(A窗体的类型); } else if (listBox选择B) { ft = typeof(B窗体的类型); }foreach (Form item in Application.OpenForms) { if (item.GetType() == ft) { item.Activate(); break; } }
不要关闭,我点A的时候让a在b前面,点B的时候让b在a前面。
// 比如 listBox1 的选择事件,其他的事件也一样 private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1选择了A) { this.Activate<A窗体的类型>(); } else if (listBox选择了B) { this.Activate<B窗体的类型>(); } }// 加上一个方法 private void Activate<T>() where T : Form { foreach (Form item in Application.OpenForms) { if (item is T) { item.Activate(); break; } } }
if (listBox选择A)
{
ft = typeof(A窗体的类型);
}
else if (listBox选择B)
{
ft = typeof(B窗体的类型);
}foreach (Form item in Application.OpenForms)
{
if (item.GetType() == ft)
{
item.Activate();
break;
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1选择了A)
{
this.Activate<A窗体的类型>();
}
else if (listBox选择了B)
{
this.Activate<B窗体的类型>();
}
}// 加上一个方法
private void Activate<T>() where T : Form
{
foreach (Form item in Application.OpenForms)
{
if (item is T)
{
item.Activate();
break;
}
}
}