设置“超时” Windows 窗体应用程序中的功能

发布于 2024-09-12 03:53:16 字数 179 浏览 0 评论 0原文

任何人都知道我如何在 Windows 窗体应用程序中构建超时功能。

该应用程序是事件驱动的,但我正在考虑以某种方式使用一个计时器,该计时器会倒计时 10 分钟,当计时器滴答一声时,我们就会让用户超时。

我遇到的问题是如何在每次移动或单击鼠标时重置计时器。

任何帮助表示赞赏。

干杯

Dows anyone know how I can build a timeout feature into a windows forms app.

The app is event driven, but I am thinking of somehow using a timer which counts down for say 10minutes, and one the timer ticks then we time out the user.

The problem I have is how can I reset the timer each time the mouse is moved or clicked.

Any help appreciated.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心安伴我暖 2024-09-19 03:53:16

您可以使用System.Windows.Forms.Timer

您可以将其从工具箱拖到设计器界面。

使用属性窗口将 Interval 属性设置为您想要的时间跨度(毫秒),Enabled 属性应设置为 false。

在 for load 上,将计时器 Enabled 属性设置为 true。

(示例中的事件处理程序是使用 C# 编写的 - 对此感到抱歉)

private void Form1_Load(object sender, EventArgs e)
{
定时器1.Enabled = true;
}

双击计时器滴答事件注册该事件,并在计时器滴答时关闭表单


私有无效timer1_Tick(对象发送者,EventArgs e)
{
关闭();
}

you can use System.Windows.Forms.Timer.

you can drag it from your toolbox to the designer surface.

Use the properties window to set the Interval Property to the time span you want(miliseconds), the Enabled property should be set to false.

on the for load set the timer Enabled property to true.

(The event handler in the sample are written using c# - sorry about that)

private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
}

Double click the timer tick event to register to the event, and close the form on the timer tick


private void timer1_Tick(object sender, EventArgs e)
{
Close();
}

沦落红尘 2024-09-19 03:53:16

将timer.Interval 设置为0 不起作用?

Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    Me.Timer1.Stop()
    Me.Timer1.Start()
End Sub

In setting timer.Interval to 0 it does not work ?

Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
    Me.Timer1.Stop()
    Me.Timer1.Start()
End Sub
北方的巷 2024-09-19 03:53:16

尽管看起来很糟糕,但我认为最好的方法是使用 system.timer 对象,设置的时间间隔最多为几毫秒。

我曾经看到的是使用全局变量来获取最后一个操作的时间,并且每次执行操作时该变量都会设置为 Now(例如使用全局函数)。在计时器已过的事件中,您检查现在是否大于 10 分钟限制的最后一个操作,并采取相应的行动。

对于多表单应用程序,您可以在每个表单上使用不同的计时器,或者仅在主表单上运行计时器。

希望有帮助。

As bad as it seems, I think the best way for that is to use a system.timer object with a set interval of a few milliseconds at most.

What I saw once is the use of a global variable that would get the time of the last action and that variable would be set to Now (using a global function for example) each time an action is performed. In your timer elapsed event, you check if now if bigger that the last action with your 10 minutes limit and act accordingly.

As for multi-form app, you could either use a different timer on each form , or only have the timer run on your main form.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文