Reputation: 3
I'm trying to generate a random colour from 7 options. All of the stack overflow posts / tutorials I've found have been ANY random colour. This is the list of the colour :
Red = New SolidColorBrush(Color.FromArgb(100, 255, 0, 0))
White = New SolidColorBrush(Color.FromArgb(100, 255, 255, 255))
Blue = New SolidColorBrush(Color.FromArgb(100, 0, 0, 255))
Yellow = New SolidColorBrush(Color.FromArgb(100, 244, 255, 16))
Green = New SolidColorBrush(Color.FromArgb(100, 0, 255, 0))
pink = New SolidColorBrush(Color.FromArgb(100, 255, 16, 22))
Brown = New SolidColorBrush(Color.FromArgb(100, 120, 37, 37))
i want to randomthem to Label1.foreground
:
Label1.Foreground = // I got Stuck at This -,-
I try to us a random number generator:
Dim randomColour As New Random
but I'm Stuck how to do that ... Pls Help Me ....
Upvotes: 0
Views: 3425
Reputation: 1117
also you can use button when clicked color change in random
Public Class Form1
Dim rnd As New Random
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.BackColor = Color.FromArgb(255, rnd.Next(255), rnd.Next(255), rnd.Next(255))
End Sub
End Class
Upvotes: 2
Reputation: 28387
You may want to use SolidBrush
.
' Create a List
Dim colorList As New List(Of SolidBrush)
' Add colors to it
colorList.Add(New SolidBrush(Color.FromArgb(100, 255, 0, 0)))
colorList.Add(New SolidBrush(Color.FromArgb(100, 255, 255, 255)))
...
' Create a random instance
Dim rnd = new Random()
' Get a random item from the list between 0 and list count
Dim randomColour = colorList(rnd.Next(0, colorList.Count))
' Assign the color to the label
Me.Label1.ForeColor = randomColour.Color
Upvotes: 1