实现方法分为两大类:窗体事件和控件事件,下面就一一展示:

一、FormClosing事件(又分以下几种方法)

a.

Private Sub frmPractise_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MessageBox.Show("确定退出吗?", "退出确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
e.Cancel = True
End If
End Sub

b.

Private Sub Practise_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MsgBox("确定退出吗?", MessageBoxButtons.OKCancel, "退出确认") = Windows.Forms.DialogResult.Cancel Then
e.Cancel = True
End If
End Sub

c.

Private Sub Practise_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim p As Integer
p = MsgBox("你真的要退出系统吗?", MsgBoxStyle.OkCancel, "提示")
If p = 2 Then
e.Cancel = True
End If
End Sub

d.(最为简单)

Private Sub Practise_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MsgBox("你确认要退出程序吗?", MsgBoxStyle.OkCancel, "退出提示") = MsgBoxResult.Cancel Then e.Cancel = True
End Sub

以上只是点击窗口关闭按钮时的用法,若直接在窗体控件上点击退出时,可以用以下方式实现:

二、Button_Click事件

Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click

        If MsgBox("是否要退出系统?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "提示") = MsgBoxResult.Yes Then
Application.Exit()
End If End Sub

最新文章

  1. Spring MVC的配置文件(XML)的几个经典案列
  2. 微信小程序之页面路由(九)
  3. Web 前端开发人员和设计师必读精华文章【系列二十六】
  4. JS之function的应用
  5. SharePoint 2013 隐藏部分Ribbon菜单
  6. 2.1.4 扫描器X-Scan查本机隐患
  7. 使用Ant发布hadoop代码到服务器
  8. C# Json数据反序列化为Dictionary并根据关键字获取指定值
  9. 使用AFNetworking 报错提示
  10. java.lang.NoSuchFieldError: INSTANCE
  11. STM32 + RT Thread OS 学习笔记[二]
  12. .net core api +swagger(一个简单的入门demo 使用codefirst+mysql)
  13. iOS 图片9切
  14. 【awesome-dotnet-core-learning】(1)-Sprache-解析器构建库
  15. [原]openstack-kilo--issue(二十二) 虚拟机的vnc console图像调用错误
  16. input点击链接另一个页面,各种操作。
  17. vue 使用element-ui upload文件上传之后怎么清空
  18. 【SVN】命令行忽略不必要的文件和文件夹
  19. IIS "rewrite.dll failed to load. The data is the error." 错误解决方法
  20. 开发组件:Supervisor

热门文章

  1. JSP验证码。
  2. Android五种数据存储方式
  3. Python中【__all__】的用法
  4. Python select IO多路复用
  5. saltstack自动化运维系列⑧SaltStack实践配置管理安装nginx-1.10.3
  6. mysql忘记root密码的处理方式
  7. JavaScript的类型自动转换高级玩法JSFuck
  8. Android Studio gradle配置详解
  9. charles mock方法及问题
  10. java 文件读取的一些方法