关于关闭窗口时的问题
我想实现关闭一个关闭form1这个事件时,出现msgbox,如果选yes就退出程序,如果选no就隐藏当前窗口,但是我的程序好像没进入if语句,不论写yes还是no都是退出程序
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim message, title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
message = "你是否退出程序执行?"
style = MsgBoxStyle.Question Or MsgBoxStyle.YesNo
title = "msgBox测试"
response = MsgBox(message, style, title)
If response = MsgBoxResult.Yes Then
End
Else
Me.hide()
End If
End Sub
[解决办法]
如果不想退出,在Form_Closing事件的参数e里,设置e.Cancel=True,表示不关闭窗口。