检查表单是否已打开 [英] Check if form is Opened
本文介绍了检查表单是否已打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我提出这个问题是为了获得更多知识.我怎么知道表单是否在我的应用程序中打开,为了不再打开它,我的意思是不要在运行时创建相同表单的实例
I give this question for more knowledge. How can I know if the form is Opened in my application or not, in order not to open it again I mean not to create an instance of the same form while it's running
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 I executes this code many times it will create more instances of the form Form2 How can I check if this form is not already opened
推荐答案
你可以这样试试:
Imports System.Linq ' need to add
If Application.OpenForms().OfType(Of Form2).Any Then
MessageBox.Show("Opened")
Else
Dim f2 As New Form2
f2.Text = "form2"
f2.Show()
End If
这篇关于检查表单是否已打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文