我在做记事本 退出时判断是否保存。点右上角的关闭用的是 Form_QueryUnload
菜单里的退出按纽用的是quit_Click
但在quit_Click事件发生时 也伴随着Form_QueryUnload事件,请问怎么解决。
在quit_Click事件中调用QueryUnload成功不了
[此贴子已经被作者于2005-6-1 21:14:46编辑过]
Private strfilename As String Private a As Boolean Private b As Integer Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If a = True Then b = MsgBox("文件已经改变是否保存?", vbYesNoCancel + vbQuestion, "question") Select Case b Case 6 Call saveas_Click Cancel = 0 Case 2 Cancel = 1 Case 7 Cancel = 0 End Select End If End Sub
Private Sub Form_Resize() rtxt.Top = 0 rtxt.Width = Me.Width - 100 rtxt.Height = Me.Height - 1000 End Sub
Private Sub new_Click() '新建 rtxt = "" End Sub
Private Sub open_Click() '打开 With cmdlog .DialogTitle = "打开 open " .Filter = "文本文件 *.txt|*.txt|word文档 *.doc|*.doc|所有文件|*.*" .ShowOpen strfilename = .FileName rtxt.LoadFile strfilename End With End Sub
Private Sub quit_Click() '退出 If a = True Then b = MsgBox("文件已经改变是否保存?", vbYesNoCancel + vbQuestion, "question") Select Case b Case 6 Call saveas_Click Unload frm Case 7 Unload frm End Select Else Unload frm End If End Sub
Private Sub rtxt_Change() 'richtestbox a = True End Sub
Private Sub saveas_Click() '另存 With cmdlog .DialogTitle = "另存为" .Filter = "文本文件 txt|*.txt|word文档 doc|*.doc|所有文件|*.*" .ShowSave strfilename = .FileName rtxt.SaveFile strfilename, 1 End With End Sub
Option Explicit
Dim bChanged As Boolean
Private Sub Command1_Click() '退出按钮 Unload Me End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Dim rtn As Long If bChanged = True Then rtn = MsgBox("文件已经改变,是否保存?", vbQuestion + vbYesNoCancel, "提示") If rtn = vbCancel Then Cancel = True ElseIf rtn = vbYes Then '保存代码 '退出 Else '不保存退出 End If End If End Sub
Private Sub Text1_Change() bChanged = True End Sub