我给这个问题提供更多的知识。我怎么知道表单是否在我的应用程序中被打开,为了不再打开它,我的意思是不要在运行时创建一个相同形式的实例
- Dim frmCollection As New FormCollection()
- frmCollection = Application.OpenForms()
- If frmCollection.Item("Form2").IsHandleCreated Then
- MsgBox("Yes Opened")
- Else
- Dim f As New Form2()
- With f
- .Text = "form2"
- .Show()
- End With
- End If
如果我多次执行这个代码,它将创建更多的Form2格式的实例
如何检查此表单是否尚未打开
你可以这样尝试:
- If Application.OpenForms().OfType(Of Form2).Any Then
- MessageBox.Show("Opened")
- Else
- Dim f2 As New Form2
- f2.Text = "form2"
- f2.Show()
- End If