VB.Net中确认退出对话框的实现
2024-08-24 21:41:48
实现方法分为两大类:窗体事件和控件事件,下面就一一展示:
一、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
最新文章
- Spring MVC的配置文件(XML)的几个经典案列
- 微信小程序之页面路由(九)
- Web 前端开发人员和设计师必读精华文章【系列二十六】
- JS之function的应用
- SharePoint 2013 隐藏部分Ribbon菜单
- 2.1.4 扫描器X-Scan查本机隐患
- 使用Ant发布hadoop代码到服务器
- C# Json数据反序列化为Dictionary并根据关键字获取指定值
- 使用AFNetworking 报错提示
- java.lang.NoSuchFieldError: INSTANCE
- STM32 + RT Thread OS 学习笔记[二]
- .net core api +swagger(一个简单的入门demo 使用codefirst+mysql)
- iOS 图片9切
- 【awesome-dotnet-core-learning】(1)-Sprache-解析器构建库
- [原]openstack-kilo--issue(二十二) 虚拟机的vnc console图像调用错误
- input点击链接另一个页面,各种操作。
- vue 使用element-ui upload文件上传之后怎么清空
- 【SVN】命令行忽略不必要的文件和文件夹
- IIS ";rewrite.dll failed to load. The data is the error."; 错误解决方法
- 开发组件:Supervisor