private frmChild as Form1'当打开第二个窗口时候,判断原来窗口 if Not frmChild is Nothing then Unload frmChild set frmChild = Nothing End If set frmChild = New Form1 frmChild.Show
在MDI窗口中,在打开新的窗口前,可先判断一下是否已经打开: if Me.ActiveForm is FormName then 已打开
判断并关闭窗口: if Me.ActiveForm is nothing then Me.ActiveForm.Unload
如果是运行时,那可以循环检查Forms.Item()
如果是设计时,那就需要用IDE的一些功能了。
if Not frmChild is Nothing then
Unload frmChild
set frmChild = Nothing
End If
set frmChild = New Form1
frmChild.Show
if Me.ActiveForm is FormName then 已打开
if Me.ActiveForm is nothing then Me.ActiveForm.Unload