VB6下退出确认的疑问

来源:百度知道 编辑:UC知道 时间:2024/07/05 08:55:20
代码如下,分别在工具栏、菜单栏、窗体右上角关闭按钮上进行退出确认,
窗体右上角的关闭按钮,无论选择是或否,都会退出
而工具栏和菜单栏,按否却不会退出,但按了是,还会进行一次询问(是或否)
请问这是什么原因?
'工具栏控制
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "BThelp"
Form_about.Show
Form_main.Enabled = False
Case "BTexit"
Call zf_Exit_yesno
End Select
End Sub
'退出确认函数
Private Sub zf_Exit_yesno()
Dim i As Integer
i = MsgBox("真的要退出吗?", vbYesNo + 32, "提示")
If i = vbYes Then
Unload Form_main
End If
End Sub
'退出
Private Sub Form_Unload(Cancel As Integer)
Call zf_Exit_yesno
End Sub
'退出
Private Sub menuQuit_Click()
Call zf_Exit_yesno
End Sub

直接这样写
private sub form_unload(Cancel as integer)
if MsgBox("确认退出?", vbQuestion+vbyesno, "退出程序")=vbno then
cancel=1
end if
end sub
然后把前面的退出程序的按钮内的代码直接改成Unload me

'请看清楚下面增加的部分,这样改就行
Option Explicit
Dim m_exit As Boolean '增加部分

Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "BThelp"
Form_about.Show
Form_main.Enabled = False
Case "BTexit"
Call zf_Exit_yesno
End Select
End Sub
'退出确认函数
Private Sub zf_Exit_yesno()
Dim i As Integer
i = MsgBox("真的要退出吗?", vbYesNo + 32, "提示")
If i = vbYes Then
m_exit = True '增加部分
Unload Form_main
End If
End Sub
'退出
Private Sub Form_Unload(Cancel As Integer)
If Not m_exit Then '增加部分
Call zf_Exit_yesno
End If
End Sub
'退出
Private Sub menuQuit