如何知道是否在vb.net中单击了“关闭"按钮(在标题栏中) [英] how to know wether Close button is clicked (in the titlebar) in vb.net

查看:402
本文介绍了如何知道是否在vb.net中单击了“关闭"按钮(在标题栏中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,每个人我仍然不知道如何知道在Visual Studio 2008中是否单击了关闭按钮,它的事件名称是什么,我该怎么做.

请我需要您的帮助
谢谢.

hey every body i still don''t understand how to know whether the close button is clicked or not in visual studio 2008 and what is its event name and how do i do it.

please i need ur help
Thanks.

推荐答案

我跟踪此问题的方法是在表单上有一个布尔变量.我在load事件中将其设置为false.如果我的表单上有一个按钮或其他控件,用户可以使用该按钮或其他控件来关闭表单,请确保在调用Form.Close之前将变量设置为true.然后,我使用FormClosing事件来捕获诸如在退出之前检查用户是否已保存的信息:

The way I track this is I have a boolean variable on my form. I set it to false in the load event. If I have a button or other control on my form that the user can use to close the form, I make sure that it sets the variable to true before it calls the Form.Close. Then I use the FormClosing event to catch things like checking if the user saved before exiting:

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If boolCloseByButton Then
           'Closed by a different button           
        Else
           'Closed by the x on the form
        End If
End Sub



希望对您有帮助



Hope this helps


您可以使用FormClosingEventArgs.CloseReason属性来检查是否单击了关闭"按钮.

You can use the FormClosingEventArgs.CloseReason property to check if the Close button was clicked.

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing  
    'You could put a Select Case statement here and take action for all
    'different types of closing conditions.      
    If e.CloseReason = System.Windows.Forms.CloseReason.UserClosing Then 
          'Closed by the x on the form or Alt-F4
    Else    
          'Closed for some other reason       
               
    End If

End Sub


这篇关于如何知道是否在vb.net中单击了“关闭"按钮(在标题栏中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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