读书人

关于关闭窗口时的有关问题

发布时间: 2012-06-01 16:46:36 作者: rapoo

关于关闭窗口时的问题
我想实现关闭一个关闭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,表示不关闭窗口。

读书人网 >VB Dotnet

热点推荐