如何在 vb.net 中处理表单关闭事件 [英] How to handle a form close event in vb.net

查看:43
本文介绍了如何在 vb.net 中处理表单关闭事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了下面的代码,但它没有显示 msgbox.这段代码有什么问题?

I have used the below code but its not showing the msgbox. What is wrong with this code ?

Private Sub frmSimple_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
       Dim result = MsgBox("Are you sure you want to Exit ?", vbYesNo)
       If result = DialogResult.Yes Then
        me.Close()
       End If
End Sub

推荐答案

此代码在表单关闭后,在处理时运行.
根据您显示表单的方式,它可能根本不会被处理.

This code runs after the form has been closed, when it's being disposed.
Depending on how you're showing the form, it might not get disposed at all.

如果要取消关闭,您需要处理FormClosing 事件并将e.Cancel 设置为True.

You need to handle the FormClosing event and set e.Cancel to True if you want to cancel the close.

这篇关于如何在 vb.net 中处理表单关闭事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆