如何判断一子窗体是否已运行(打开)
各位网友好,在VB中,如何判断一子窗体是否打开(运行),代码如何写出。请指导,谢谢
目前的我想到的办法是遍类所有的窗体,然后判断名字来判断。
如果从开始就做准备,打开指定窗体时,就设置一个变量值,关闭时再设置一个值 就更好。
'判断是否打开了form1,只允许打开一个 Public Form1YN As Boolean
Private Sub Form_Load() Form1YN = True End Sub Private Sub Form_Unload(Cancel As Integer) Form1YN = False End Sub
Private Sub Command1_Click() '标志法 Dim p As Form1 If Not Form1YN Then Set p = New Form1 p.Show Else MsgBox "Form1 已打开" End If End Sub
Private Sub Command2_Click() '遍类法 Dim p As Form For Each p In Forms If p.Name = "Form1" Then MsgBox "Form1 已打开" Exit For End If Next End Sub