Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
839 views
in Technique[技术] by (71.8m points)

vb.net - How to determine inactivity on a winform

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.

Here is what I have.

    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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...