如何确定 Winform 上的不活动状态 [英] How to determine inactivity on a winform

查看:28
本文介绍了如何确定 Winform 上的不活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示在我的应用程序顶部的 winform.如果表单在一段时间内处于非活动状态,我想要的是将表单设置为 20% 的不透明度.现在,当我单击一个按钮时,我有一个类似的事件在运行,表单的大小会发生变化.我在执行转换时使用计时器设置表单不透明度.如果表单上没有活动,我现在可以使用类似的代码来设置不透明度,我只是不知道如何检测不活动.

I have a winform that is displayed at the top of my application. What I would like to is have the form set to 20% opacity if it has been inactive for a certain amount of time. Right now I have a similar event running when I click a button, the size of the form changes. I use a timer to set the form opacity while is performing the transition. I now I can use similar code to set opacity if there is inactivity on the form, I just do not know how to dectect inactivity.

这是我所拥有的.

    Private Sub btnShowForm_Click(sender As Object, e As EventArgs) Handles btnShowForm.Click

    'This procedure runs when the btnShowForm
    'button is clicked. The procedure maximizes the size
    'of the form, hides the left right button and displays the button
    'to expand the form. It also moves the combobox down. 
    'It calls the viewButtons function to hide and
    'display the right buttons.     
    'The procedure also uses a timer to set the fade in and out the
    'form when is min or max

    Me.Height = 126

    Me.Opacity = 0.2                   'About 20%
    timNavigationPage.Interval = 100   'about one-tenth of a second
    timNavigationPage.Start()          'Start the timer


    cmbViewDataSheets.Location = New Point(741, 89)


    viewButtons(False, True)

End Sub

Private Sub timNavigationPage_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timNavigationPage.Tick

    'Initialize the timer to fade form.

    Dim x As Double = 0.075

    If Me.Opacity <= 1 Then
        Me.Opacity += x     'increment opacity with 7.5%

    ElseIf Me.Opacity + x > 1 Then
        timNavigationPage.Stop()       'Stop the timer then the opacity has reached a 100%

    End If

End Sub

推荐答案

这里有一个很棒的 示例 使用 user32.dll

Here is a great example using the GetLastInputInfo from the user32.dll

这篇关于如何确定 Winform 上的不活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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