如何判断一子窗体是否已运行(打开)
各位网友好,在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