2
我需要在VB.Net vs2008中打開MDI子的一個實例...此代碼打開同一MDI子的多個重複項;我對C#這個答案Prevent duplicate MDI children forms但沒有找到一個VB.Net VS 2008避免打開重複的mdi子
Dim myChild As New Form1()
myChild.MdiParent = Me
myChild.Show()
我需要在VB.Net vs2008中打開MDI子的一個實例...此代碼打開同一MDI子的多個重複項;我對C#這個答案Prevent duplicate MDI children forms但沒有找到一個VB.Net VS 2008避免打開重複的mdi子
Dim myChild As New Form1()
myChild.MdiParent = Me
myChild.Show()
這是弗雷德裏克·莫克的代碼VB.Net版本:
For Each f As Form In Application.OpenForms
If TypeOf f Is Form1 Then
f.Activate()
Return
End If
Next
Dim myChild As New Form1
myChild.MdiParent = Me
myChild.Show()
試試這個
private void button1_Click(object sender, EventArgs e)
{
FormCollection fc = Application.OpenForms;
bool FormFound = false;
foreach (Form frm in fc)
{
if (frm.Name == "Form2")
{
frm.Focus();
FormFound = true;
}
}
if (FormFound == false)
{
Form2 f = new Form2();
f.Show();
}
}