FormClosing事件无法正常运行 [英] FormClosing event doesn't work as I want

查看:67
本文介绍了FormClosing事件无法正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们!
首先,我阅读了其他类似的主题,但是还没有看到完整的匹配.

Hi friends!
First, I have read other similar threads but I haven't seen a complete match.

这是我的VB.NET应用程序.我希望用户通过单击右上角的X关闭表单/应用程序时注销该用户(以防止该用户看上去在线而不是在线).

It is my VB.NET app. I want the user to be logged out when a user closes the form/application by clicking the X at the right-top (to prevent the user from appearing to be online while not).

现在,我为LoggOff创建了一个子项,将其放入模块中,并在需要时调用它.因此,我转到属性,然后双击"Form Closing".事件,用于编写FormClosing的代码.在FormClose内部,我将其称为注销".子解释 当然,上面的内容现在是当用户单击顶部的大关闭"X"时,他/她已注销.但这是一个问题;

Now, I created a sub for LoggOff, put it in a module and call it whenever I want it. So I went to properties and double-clicked"Form Closing" event to write the code for FormClosing. Inside FormClose I call the "LogOff" sub explained above, ofcourse, now when the user clicks the big close 'X' at the top, he/she is logged off.But there is a problem;

要加载的第一个表单是登录表单,之后是另一个表单,例如"Welcome".将打开并登录"将被关闭(通过welcome.open,me.close),现在的问题是,每当执行me.close时,FormClosing中的所有代码 事件也会运行,这意味着终止应用程序.

The first form to load is the login form after which another form, say "Welcome" will be opened and "login" will be closed (by welcome.open, me.close), now the problem is, whenever me.close is executed, all the code in the FormClosing event is also run, which means terminating the application.

每当我只想关闭一个表单并打开另一个表单(我不想只隐藏表单)时,代码都会注销用户并关闭应用程序.我该如何区分用户点击大X的关闭和程序员与me.close的关闭.close???

Whenever I just want to close one form and open another one (I don't want to just hide forms) the code will log the user off and close the application. How can I differentiate the closing of a user hitting the big X and the closing of a programmer with me.close???

非常感谢您的投入.
弗兰克!

Many thanks for any input.
Frank!

推荐答案


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddHandler Application.ApplicationExit, AddressOf OnApplicationExit
    End Sub

    Private Shared Sub OnApplicationExit(ByVal sender As Object, ByVal e As EventArgs)
        'Log off here
    End Sub


将代码放入只可以打开一次的表单中,就像您的欢迎表单一样!!


Put the code in a form that will be opened only one time, like your welcome form !!


这篇关于FormClosing事件无法正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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