Okay so I've been trying for a few days now and just can not seem to figure this algorithm out. Right now I'm trying it with a while loop but still not working.

Basically here is my snippet. It's on a timer for 10ms.

void colorScrollRotation(object sender, EventArgs e)
        {
            int colorRed = 10;
            int colorGreen = 30;
            int colorBlue = 10;
            int colorCount = 0;

            while (colorCount != 500)
            {
                colorRed++;
                colorGreen++;
                colorBlue++;

                if (colorGreen == 192)
                {
                    colorRed = 10;
                    colorBlue = 10;
                    colorGreen = 30;
                }

                agInc.ForeColor = Color.FromArgb(colorRed, colorGreen, colorBlue);
                colorCount = colorRed + colorGreen + colorBlue;
            }
        }

Now it changes the color the first 10ms, but then never changes again. I just want a simple green major hue shift for my label. Any help would be appreciated.

It looks like your code it taking longer to run than a tick event, so it just gets set back each loop. Try something like this:

Color c = label1.ForeColor;

            int colorRed = c.R;
            int colorGreen = c.G;
            int colorBlue = c.B;

            colorRed++;
            colorGreen++;
            colorBlue++;

            if (colorGreen == 192) {
                colorRed = 10;
                colorBlue = 10;
                colorGreen = 30;
            }


            label1.ForeColor = Color.FromArgb(colorRed, colorGreen, colorBlue);

That didn't work either unfortunately, at first I thought it would but evidently I'm wrong as always. If I'm correct that's going to get the current rgb values for my label, then set each color to that value, finally incrementing it by one. That should work flawlessly but yet it stays the exact same shade of green. I even bumped the timer interval up to 50ms. I can't have it going too slow so I need the algorithm to be fast as well. Momerath, I modified the snippet you posted and made it add by 5 instead of just a ++ but that didn't work either. I can't seem to figure this out and any help is still appreciated. Once again much thanks to whoever helps me solve this problem.

// Timer set up. (Automatically made by VS2010 Professional.)
this.colorScroll.Interval = 50;
this.colorScroll.Tick += new System.EventHandler(this.colorScrollRotation);

// This is the timer tick event. (They are in their own .cs files.)
void colorScrollRotation(object sender, EventArgs e)
        {
            Color colorMe = agInc.ForeColor;

            int colorRed = colorMe.R;
            int colorGreen = colorMe.G;
            int colorBlue = colorMe.B;

            colorRed = colorRed + 5;
            colorGreen = colorGreen + 5;
            colorBlue = colorBlue + 5;

            if (colorGreen == 192)
            {
                colorRed = 10;
                colorBlue = 10;
                colorGreen = 30;
            }
        }

Odd, works fine on my system. I do notice that you don't set the foreground color in your code, did you forget that line?

Thank you very, very, very much. Yeah by stupid newbie mistake I forgot my assignment to the label. Hehe I feel dumb now. :( Anyways, much thanks to you, and here is the snippet finale for anyone who would like to use it in the future. :)

void colorScrollRotation(object sender, EventArgs e)
        {
            Color colorMe = agInc.ForeColor;

            int colorRed = colorMe.R;
            int colorGreen = colorMe.G;
            int colorBlue = colorMe.B;

            colorGreen++;

            // This is so it won't go above 255, it causes bugs if it does.
            if (colorGreen >= 255)
            {
                colorGreen = 0;
            }

            // Assigns the colors back to the label named 'agInc'.
            agInc.ForeColor = Color.FromArgb(colorRed, colorGreen, colorBlue);
        }

Much thanks to Momerath. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.