How to make a rainbow label!

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
8 posts Page 1 of 1
Contributors
User avatar
code it
VIP - Site Partner
VIP - Site Partner
Posts: 821
Joined: Sun Oct 10, 2010 3:02 pm

How to make a rainbow label!
code it
Add 1 Label and make the forecolor Red
Add 1 timer,set interval to '1' and enabled=true


Now code

Timer1_Tick:
Code: Select all
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Label1.ForeColor = Color.Red Then
            Label1.ForeColor = Color.Orange
        Else
            If Label1.ForeColor = Color.Orange Then
                Label1.ForeColor = Color.Yellow
            Else
                If Label1.ForeColor = Color.Yellow Then
                    Label1.ForeColor = Color.Green
                Else
                    If Label1.ForeColor = Color.Green Then
                        Label1.ForeColor = Color.Blue
                    Else
                        If Label1.ForeColor = Color.Blue Then
                            Label1.ForeColor = Color.Purple
                        Else
                            If Label1.ForeColor = Color.Purple Then
                                Label1.ForeColor = Color.Red
                            End If
                        End If
                    End If
                End If
            End If
        End If

Your done :D
User avatar
Zulf
Serious Programmer
Serious Programmer
Posts: 441
Joined: Fri Jun 11, 2010 7:46 am

Re: How to make a rainbow label!
Zulf
Or on the timer event you could use:
Code: Select all
Dim a as Array
a = { Color.Red , Color.Blue, Color.Green, Color.Purple, Color.Yellow }
Label1.ForeColor = a[0]
Instead of a[0] you could make it pull a random number between 0-4.
Image
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: How to make a rainbow label!
GoodGuy17
I created mine like Code It did. Mind explaining your way in VB.NET, Zulf?
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

Re: How to make a rainbow label!
zachman61
Lol you guys did the exact colors i did in my program in the same order.
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
code it
VIP - Site Partner
VIP - Site Partner
Posts: 821
Joined: Sun Oct 10, 2010 3:02 pm

Re: How to make a rainbow label!
code it
Thanks for the comments cooll;
User avatar
Zulf
Serious Programmer
Serious Programmer
Posts: 441
Joined: Fri Jun 11, 2010 7:46 am

Re: How to make a rainbow label!
Zulf
GoodGuy17 wrote:
I created mine like Code It did. Mind explaining your way in VB.NET, Zulf?
I'm not good in VB.NET, but that's what I did to pull the colors from a specific selection of colors:
Code: Select all
private void timer1_Tick(object sender, EventArgs e)
{
      flashLabel(label1);
}

public void flashLabel(Label l)
{
      String[] colorArray = { System.Drawing.Color.Red, System.Drawing.Color.Blue, System.Drawing.Color.Green };
      l.ForeColor = colorArray[random(0,2)];
}

public int random(int min, int max)
{
      Random rand = new Random();
      int rand0;
      rand0 = rand.Next(min, max);
}
To change the label color with any random RGB color I used:
Code: Select all
private void timer1_Tick(object sender, EventArgs e)
{
      flashLabel(label1);
}

public void flashLabel(Label l)
{
      l.ForeColor = System.Drawing.Color.FromArgb(random(0,255),random(0,255),random(0,255));
}

public int random(int min, int max)
{
      Random rand = new Random();
      int rand0;
      rand0 = rand.Next(min, max);
}
:) Zulf got skills.
Image
User avatar
iLenkaa
Top Poster
Top Poster
Posts: 170
Joined: Mon Nov 01, 2010 1:17 pm

Re: How to make a rainbow label!
iLenkaa
I would change the interval to 75 or something.
Because when you set it to 1, it's just something flickering...

But still: I love it! :)
Image
Image
Image
Image
Image
Image
User avatar
code it
VIP - Site Partner
VIP - Site Partner
Posts: 821
Joined: Sun Oct 10, 2010 3:02 pm

Re: How to make a rainbow label!
code it
Haha I know but thanks iLeenka ! clapper;
8 posts Page 1 of 1
Return to “Tutorials”