码迷,mamicode.com
首页 > Web开发 > 详细

VB.Net中确认退出对话框的实现

时间:2014-10-24 18:40:28      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:style   io   os   ar   for   sp   on   log   cti   

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

    一、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

VB.Net中确认退出对话框的实现

标签:style   io   os   ar   for   sp   on   log   cti   

原文地址:http://www.cnblogs.com/ilookbo/p/4048594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!