vb 怎样让程序在点击关闭按钮时弹出提示框?

如题所述

第1个回答  2018-03-10

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

If MsgBox("确定要退出?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then

e.Cancel = True

End If

End Sub

本回答被网友采纳
第2个回答  2018-02-04
Private Sub cmdEXIT_Click() '退出按钮

Private Sub Form_Unload(Cancel As Integer) '窗体的关闭按钮

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "是否要确定退出 ?" ' 定义信息。
Style = vbYesNo + vbCritical + vbDefaultButton2 ' 定义按钮。
Title = "程序退出对话框" ' 定义标题。
Help = "DEMO.HLP" ' 定义帮助文件。
Ctxt = 1000 ' 定义标题
' 上下文。
' 显示信息。
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' 用户按下“是”。
MyString = "Yes" ' 完成某操作。
unload me '关闭程序
End If
End Sub
相似回答