|
-
Jul 12th, 2007, 09:43 AM
#1
Thread Starter
Fanatic Member
[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
-
Jul 12th, 2007, 09:56 AM
#2
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
-
Jul 12th, 2007, 10:18 AM
#3
Thread Starter
Fanatic Member
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.
-
Jul 12th, 2007, 10:30 AM
#4
Hyperactive Member
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
-
Jul 12th, 2007, 10:32 AM
#5
Hyperactive Member
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
-
Jul 12th, 2007, 10:37 AM
#6
Hyperactive Member
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.
-
Jul 12th, 2007, 10:38 AM
#7
Re: [2005] How to set applications opacity to 75% after application is inactive for 30sec
 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.
-
Jul 12th, 2007, 10:54 AM
#8
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|