zoukankan      html  css  js  c++  java
  • VB.Net中确认退出对话框的实现

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

        一、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
  • 相关阅读:
    C#学习之Enum
    Ten MustHave Tools Every Developer Should Download Now
    C#学习之Random
    C#学习之Exception
    WCF Data Contract之KnownType
    ESQL应该注意的地方
    Windows 安全认证是如何进行的?
    十个必备的.NET开发小工具
    c#中判断一个process是32bit还是64bit
    怎么用python和javascript把多张png拼成一个gif
  • 原文地址:https://www.cnblogs.com/ilookbo/p/4048594.html
Copyright © 2011-2022 走看看