By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Loopin trough colors

P: n/a
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
Jun 13 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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!
*************************************************
"Nedim" <Ne***@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
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

Jun 13 '06 #2

P: n/a
yes, that is correct, i would like it to scroll trough all the colors i have
set upon pressing the button.

"Cowboy (Gregory A. Beamer)" wrote:
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!
*************************************************
"Nedim" <Ne***@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
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


Jun 13 '06 #3

P: n/a
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
"Nedim" <Ne***@discussions.microsoft.com> schreef in bericht
news:1D**********************************@microsof t.com...
yes, that is correct, i would like it to scroll trough all the colors i
have
set upon pressing the button.

"Cowboy (Gregory A. Beamer)" wrote:
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!
*************************************************
"Nedim" <Ne***@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
> 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
>
>


Jun 13 '06 #4

P: n/a
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
Nedim wrote:
yes, that is correct, i would like it to scroll trough all the colors i have
set upon pressing the button.

"Cowboy (Gregory A. Beamer)" wrote:
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!
*************************************************
"Nedim" <Ne***@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
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

Jun 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.