VB记事本的form Unload

来源:百度知道 编辑:UC知道 时间:2024/06/03 06:13:30
If Len(RichTextBox1.Text) = 0 Then
RichTextBox1.Text = ""
Form1.Caption = 无标题 & " - 记事本"
Else
msg1 = MsgBox("文本已更改,是否要保存", 67, "记事本")
If msg1 = vbNo Then
RichTextBox1.Text = ""
End
ElseIf msg1 = vbYes Then
CommonDialog1.Filter = "文本文档(*.txt)|*.txt"
CommonDialog1.ShowSave
FileType = CommonDialog1.FileTitle
FileName = CommonDialog1.FileName
RichTextBox1.SaveFile FileName, rtfText
Form1.Caption = Dir(FileName) & " - 记事本"
ElseIf msg1 <> vbCancel Then

End If
End If

点关闭时弹出提示 是=关闭 否=弹出保存窗口
现在点了取消要让他不关闭程序 返回窗口 如何写啊
poi123p82的不对。。。
2楼的匿名也不对

加入一条语句:
Cancel = 1
窗体就不会关闭了
如果是Cancel = 0窗体就会关闭

Cancel变量是传递给Form_Unload过程的参数,表示是否关闭窗体(1是取消关闭,0是不取消关闭),可以不用定义直接使用

ElseIf msg1 = vbCancel Then
Exit sub
End If

你代码这样就行了。直接返回到窗口 then后面什么都不用写。