-
Jan 31st, 2008, 07:08 AM
#1
Thread Starter
Member
[2005] image changing at timer interval
Hi, I've had a problem with changing my Picture Box's image at a timer interval.
The timer starts as disabled, and when enabled it has an interval of 1000.
Here's the code:
Code:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If img_ball.Image Is Bouncing_Ball.My.Resources.ball2 Then
img_ball.Image = Bouncing_Ball.My.Resources.ball1
Else
If img_ball.Image Is Bouncing_Ball.My.Resources.ball1 Then
img_ball.Image = Bouncing_Ball.My.Resources.ball2
End If
End If
End Sub
-
Jan 31st, 2008, 07:13 AM
#2
Re: [2005] image changing at timer interval
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 31st, 2008, 07:16 AM
#3
Thread Starter
Member
Re: [2005] image changing at timer interval
The image doesn't change, it should invert the colors, but it doesn't.
-
Jan 31st, 2008, 07:18 AM
#4
Addicted Member
Re: [2005] image changing at timer interval
Check the initial starting values for the Timer object. Also set this object in Enabled state initially loading the application. Check the Properties values during design time of the Timer object.
Regards
Srinivasan Baskaran
India
-
Jan 31st, 2008, 08:29 AM
#5
Re: [2005] image changing at timer interval
The problem is that your If conditions are ALWAYS going to evaluate to False. Every time you get a property value from My.Resources it creates a new object. If you get the same property twice it will return a different object each time, so the first object is not the same object as the second, so a comparison will always return False. What you need to do is get each resource once and once only:
vb.net Code:
Private ball1 As Image = My.Resources.ball1 Private ball2 As Image = My.Resources.ball2
Now your code becomes:
vb.net Code:
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick If img_ball.Image Is Me.ball2 Then img_ball.Image = Me.ball1 Else If img_ball.Image Is Me.ball1 Then img_ball.Image = Me.ball2 End If End Sub
Then you'll be referring to the same two Image objects every time and it will work.
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
|