新建From1(窗体),代码:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim myval As Integer
myval = MsgBox("真的要关闭窗口吗?", vbYesNo, "关闭窗口程序")
'返回值vbYes
If myval = vbYes Then
'退出程序
End
Else
Cancel = 1
End If
End Sub
你可以试试点击X掉窗体。