3 Replies - 8999 Views - Last Post: 24 July 2009 - 10:22 AM Rate Topic: -----

#1 Mythi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 03-February 09

Colour change in vb using timer control

Post icon  Posted 24 July 2009 - 06:50 AM

Here i want to change the colour of the text in label box continuously. Is this coding correct? While compiling only once the colour is changing.
Dim i, j As Integer
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
For i = 0 To 30
For j = i To 30
Label1.ForeColor = &HFF80FF
Label1.ForeColor = &HFF&
Next j
Next i
End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Colour change in vb using timer control

#2 sscheider  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 55
  • Joined: 14-May 09

Re: Colour change in vb using timer control

Posted 24 July 2009 - 07:02 AM

In vb6, you can try to use
Label1.Refresh
after you change the colors. You may run into threading issues with the user trying to enter something and this trying to change colors at the same time.

This post has been edited by sscheider: 24 July 2009 - 07:04 AM

Was This Post Helpful? 0
  • +
  • -

#3 vb5prgrmr  Icon User is offline

  • D.I.C Lover

Reputation: 109
  • View blog
  • Posts: 1,016
  • Joined: 21-March 09

Re: Colour change in vb using timer control

Posted 24 July 2009 - 08:59 AM

That is because of the way you have your code... Meaning the two color changes are happening so fast that the system does not have a chance to update the graphics of the system (one of the slowest parts of any system.).

Now something like this should work...
Option Explicit

Dim OnlyTwoColorChoices As Boolean

Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
If OnlyTwoColorChoices = True Then
  Label1.ForeColor = vbRed
Else
  Label1.ForeColor = vbBlue
End If
OnlyTwoColorChoices = Not OnlyTwoColorChoices
End Sub





Good Luck
Was This Post Helpful? 0
  • +
  • -

#4 Quin  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 19
  • View blog
  • Posts: 382
  • Joined: 16-October 08

Re: Colour change in vb using timer control

Posted 24 July 2009 - 10:22 AM

hehe, I remember doing this in the first week of programming - shame I cannot remember it.
Its pretty simple though, I know that much :)
And I mean simple! No if statements, no nothing. Literally, the Timer and a line of code to make it switch colour.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1