首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

VB.net怎么实现关闭窗口前询问是否要关闭

2012-03-24 
VB.net如何实现关闭窗口前询问是否要关闭? 一头雾水。各位高手请不吝赐教![解决办法]Private Sub MDImain_F

VB.net如何实现关闭窗口前询问是否要关闭?

一头雾水。各位高手请不吝赐教!

[解决办法]
Private Sub MDImain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
MessageBox.Show( "是否确定退出!!! ", MessageBoxButtons.YesNo)
End Sub
[解决办法]
使用:Form.Closing 事件
[解决办法]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If MsgBox( "是否关闭 ", MsgBoxStyle.Question Or MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
Me.Dispose()
End If
End Sub

也就是写一个MSGBOX询问是否关闭,有YES和NO两个选项,当点击YES时,执行ME.DISPOSE。关闭窗口。
[解决办法]

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

If MsgBox( "是否关闭 ", MsgBoxStyle.YesNo, "提示 ") = MsgBoxResult.Yes Then
Me.Close()
Else
Exit Sub
End If

End Sub

[解决办法]
Private Sub AskForExit(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

'退出操作确认
Dim close As DialogResult
close = MessageBox.Show( "确认要退出? ", "提示 ", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk)
If close = Windows.Forms.DialogResult.Yes Then
Me.Dispose()
Else
e.Cancel = True
End If
End Sub

热点排行