Results 1 to 8 of 8

Thread: [2005] How to set applications opacity to 75% after application is inactive for 30sec

  1. #1

    Thread Starter
    Fanatic Member Lerroy_Jenkins's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    661

    Question [2005] How to set applications opacity to 75% after application is inactive for 30sec

    I want to set the application to gradually fade to 75% opacity - This I can do.

    But, I want this event to happen only when the application has been inactive for 30 seconds.

    So, I have 2 timers, 1 to count down from 30, when hits 0, second timer counts until opacity = 75%, this, I can do.

    But, I want the 1st timer to be reset if the application is being used. Say, pressing a button, or the user is typing.

    Any ideas guys?

    L.Jenkins
    Lerroy

    "η β π", or "Eta Beta Pi" (Eat A Better Pie)

    01001000
    01000101
    01001100
    01010000


    My Own Code - WordCounter

    Useful Forum Links -Reputation - What is it?

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] How to set applications opacity to 75% after application is inactive for 3

    You could use an event handler and attach it to a few relevant events.


    edit: whoops, wrong language.

    Code:
    Me.KeyPreview = True
    AddHandler Me.KeyDown, AddressOf doThings
    AddHandler Me.Click, AddressOf doThings
    
    For Each c As Control In Me.Controls
      AddHandler c.Click, AddressOf doThings
    Next

  3. #3

    Thread Starter
    Fanatic Member Lerroy_Jenkins's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    661

    Re: [2005] How to set applications opacity to 75% after application is inactive for 30sec

    Can you please expand on that code a little penagate? I dont understand what is happening.
    Lerroy

    "η β π", or "Eta Beta Pi" (Eat A Better Pie)

    01001000
    01000101
    01001100
    01010000


    My Own Code - WordCounter

    Useful Forum Links -Reputation - What is it?

  4. #4
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] How to set applications opacity to 75% after application is inactive for 3

    would you create your sub routine

    doThings()
    reset timer
    set opacity

  5. #5
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: [2005] How to set applications opacity to 75% after application is inactive for 30sec

    You could declare two variables. One as integer and one as boolean. See below, not the prettiest but it works.

    Code:
     Dim isActive As Boolean = True
     Dim tick As Integer = 0
    
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged 
            If isActive = False Then
                ChangeStatus()
            End If
            tick = 0
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If tick = 30 Then
                ChangeStatus()
            Else
                tick = tick + 1
            End If
        End Sub
    
        Private Sub ChangeStatus()
    
            If isActive = False Then
                isActive = True
                Timer1.Enabled = True
                Me.Opacity = 1
                tick = 0
            Else
                Timer1.Enabled = False
                isActive = False
    
                Me.Opacity = 0.25
    
            End If
        End Sub
    
        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            If isActive = False Then
                ChangeStatus()
            End If
        End Sub

  6. #6
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] How to set applications opacity to 75% after application is inactive for 30sec

    The only thing is that it won't handle all the controls on the form, only if the text is changed.. But you have the right idea with the CheckStatus() sub routine.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] How to set applications opacity to 75% after application is inactive for 30sec

    Quote Originally Posted by Lerroy_Jenkins
    Can you please expand on that code a little penagate? I dont understand what is happening.
    The KeyPreview property of the form allows it to receive keyboard events before its controls do.
    AddHandler is a VB.NET statement used to attach an event handler to a particular event.

  8. #8
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Re: [2005] How to set applications opacity to 75% after application is inactive for 30sec

    Code:
    Dim isActive As Boolean = True
    Dim tick As Integer = 0
    
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If tick = 30 Then
                ChangeStatus()
            Else
                tick = tick + 1
            End If
        End Sub
    
        Private Sub ChangeStatus()
    
            If isActive = False Then
                isActive = True
                Timer1.Enabled = True
                Me.Opacity = 1
                tick = 0
            Else
                Timer1.Enabled = False
                isActive = False
    
                Me.Opacity = 0.25
    
            End If
        End Sub
    
    'Two resetTicks sub for different control signatures
        Private Sub ResetTick(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
            tick = 0
            If isActive = False Then
                ChangeStatus()
            End If
        End Sub
    
        Private Sub ResetTick(ByVal sender As System.Object, ByVal e As System.EventArgs)
            tick = 0
            If isActive = False Then
                ChangeStatus()
            End If
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Me.KeyPreview = True
            AddHandler Me.KeyPress, AddressOf ResetTick
            AddHandler Me.Click, AddressOf ResetTick
    
            For Each c As Control In Me.Controls
                AddHandler c.Click, AddressOf ResetTick
            Next
        End Sub
    Thank you Penagate for teaching me something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width