Loopin trough colors

G

Guest

first let me say sorry if this is in the wrong place, i'm pretty new to
programming and to be honest i am a bit intimidated by these forums.

now that i've got that out of the way, i was bored and decided to make a
small text application in Visual Basic 2005,

i have one list box, one label and ten buttons.

the list box has 8 colors listed, and when one of them is selected and the
OK button clicked the text in the label changes color, the same with other 8
buttons, but instead of selecting a color from the list the other buttons
change the color of the text directly.

the problem is the tenth button, it's supposed to loop trough all 8 colors,
but it skips directly to the last one (purple) and stays there, the code i
used is this:



Dim myColor() As Color = {Color.Blue, Color.Red, Color.Green,
Color.Yellow, Color.Black, Color.White, Color.Orange, Color.Purple}

Dim textcollor As Color
For Each textcollor In myColor
Label1.ForeColor = (textcollor)
Next
 
C

Cowboy \(Gregory A. Beamer\)

You want to see it scroll through the colors? If so, you need to pause and
paint after each change. Otherwise, it is changing, but not painting until
the entire loop is done. Am I understanding your desire correctly?

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
G

Guest

yes, that is correct, i would like it to scroll trough all the colors i have
set upon pressing the button.
 
C

Cor Ligthert [MVP]

Nedim,

To do it step by step.

If you make a same array for your labels as for your collors than you can
do.

for i as integer = 0 to myColor.lenght
mylabelInArray(i).ForeColor = mycolor(i)
next

There are endless alternatives by the way

I hope this helps,

Cor

Assuming that your textboxes are in the same sequence and are
 
G

Guest

When you set the label color, a message is sent to the control to make
it change it's color. Use the DoEvents method to process the message
queue, then do nothing for a while.

Dim textColor As Color
For Each textColor In myColor
Label1.ForeColor = textColor
DoEvents
Thread.Sleep(500)
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top