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
Add 1 Label and make the forecolor Red
Add 1 timer,set interval to '1' and enabled=true
Now code
Timer1_Tick:
Your done
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

Or on the timer event you could use:
Code: Select all
Instead of a[0] you could make it pull a random number between 0-4.Dim a as Array
a = { Color.Red , Color.Blue, Color.Green, Color.Purple, Color.Yellow }
Label1.ForeColor = a[0]
I created mine like Code It did. Mind explaining your way in VB.NET, Zulf?
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 

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
To change the label color with any random RGB color I used:
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);
}
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);
}

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!
Because when you set it to 1, it's just something flickering...
But still: I love it!

8 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023