【发布时间】:2015-04-09 17:31:11
【问题描述】:
我有一个在 VB.NET 2010 中创建的 Windows 窗体应用程序,现在我需要实现自动注销。 我正在考虑使用一个计时器,它会在每个事件中重置它或保存用户执行的每个操作的时间戳,问题是我如何检测每个事件。
应用程序有几个在运行时创建的控件和一些子 Windows 窗体。
或者也许有人对如何实现该目标有更好的想法。(在一段时间不活动后从应用程序中注销用户。
编辑: Anthony 的代码从 C# 转换为 VB
Class MessageFilter
Implements IMessageFilter
Public Function PreFilterMessage(ByRef m As Message) As Boolean
Const WM_KEYDOWN As Integer = &H100
Const WM_MOUSELEAVE As Integer = &H2A3
Select Case m.Msg
Case WM_KEYDOWN, WM_MOUSELEAVE
' Do something to indicate the user is still active.
Exit Select
End Select
' Returning true means that this message should stop here,
' we aren't actually filtering messages, so we need to return false.
Return False
End Function
End Class
我在 WinForm 类和一个单独的类中尝试了这段代码,结果相同。 “类 'MessageFilter' 必须为接口 'System.Windows.Forms.IMessageFilter' 实现 'Function PreFilterMessage(ByRef m As Message) As Boolean'。”
已解决: 转换中的错误出现在必须如下的函数签名中。
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
编辑 2: 要删除过滤器,我以这种方式声明过滤器
Public Class Form1
Friend MyMsgFilter As New MessageFilter()
End Class
然后,当我需要添加消息过滤器时
Application.AddMessageFilter(MyMsgFilter)
以及何时需要删除它
Application.RemoveMessageFilter(MyMsgFilter)
非常感谢安东尼。
【问题讨论】:
标签: vb.net winforms events logout