VB.Net中确认退出对话框的实现
发布时间:2020-12-17 08:14:52 所属栏目:百科 来源:网络整理
导读:在敲代码的时候,为了更加人性化的设计,我们在用户退出系统之前需要进行提示,如下图: 实现方法分为两大类:窗体事件和控件事件,下面就一一展示: 一、FormClosing事件(又分以下几种方法) a. Private Sub frmPractise_FormClosing(ByVal sender As Obje
在敲代码的时候,为了更加人性化的设计,我们在用户退出系统之前需要进行提示,如下图:
实现方法分为两大类:窗体事件和控件事件,下面就一一展示:
一、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
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
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("你确认要退出程序吗?","退出提示") = 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |