MDI子窗体中Unload Me为何未能触发Unload事件和QueryUnload事件
正在做一个多文档同时打开的小程序,自然用到MDI。
打开文档的子窗体名称为frmNote,当打开文档时,用下面的代码
'为了方便管理子窗体,将它们的引用放在Wins数组中
Set Wins(Index) = New frmNote
Wins(Index).Show
'没有直接Unload Wins(Index),因为有其他方面的考虑
Public Sub CloseMe()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBox "Note Form_Unload"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer,UnloadMode As Integer)
MsgBox "Note Form_QueryUnload"
End Sub
Option Explicit
Private Sub MDIForm_Unload(Cancel As Integer)
Dim frm As Form
Dim i As Long
If MsgBox("确定要退出系统吗?", vbYesNo, App.Title) = vbYes Then
For Each frm In Forms
If Not frm Is Nothing Then
Unload frm
End If
Next
End If
Set frm = Nothing
End Sub
'Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
' Dim frm As Form
' Dim i As Long
'
' If MsgBox("确定要退出系统吗?", vbYesNo, App.Title) = vbYes Then
' For Each frm In Forms
' i = i + 1
' Debug.Print i
' If Not frm Is Nothing Then
' Unload frm
' End If
' Next
' End If
'
' Set frm = Nothing
'End Sub
Private Sub mnuFAdd_Click()
Dim newfrm As New Form1
newfrm.Show
Set newfrm = Nothing
End Sub