lundi 30 décembre 2019

Label background color mix

I have three labels and one button. I want to randomize the background color for label1 and label2, on the condition that not come the same color in label1 and label2, and with the click of a button I want to get label3 background color, which is a mixed color between label1 color and label2 color. In my code i have colorlist with some colors. I want to randomize colors that are included in my colorlist only thanks for your help

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    ' Create a List
    Dim colorList As New List(Of SolidBrush)

    ' Add colors to it
    'red
    colorList.Add(New SolidBrush(Color.FromArgb(100, 255, 0, 0)))
    'white
    colorList.Add(New SolidBrush(Color.FromArgb(100, 255, 255, 255)))
    'Blue 
    colorList.Add(New SolidBrush(Color.FromArgb(100, 0, 0, 255)))
    'Yellow 
    colorList.Add(New SolidBrush(Color.FromArgb(100, 244, 255, 16)))
    'Green 
    colorList.Add(New SolidBrush(Color.FromArgb(100, 0, 255, 0)))
    'Pink 
    colorList.Add(New SolidBrush(Color.FromArgb(100, 255, 16, 22)))
    'Brown 
    colorList.Add(New SolidBrush(Color.FromArgb(100, 120, 37, 37)))
    Dim rnd = New Random()

    ' Get a random item from the list between 0 and list count
    Dim randomColour = colorList(rnd.Next(0, colorList.Count))
    Dim randomColour1 = colorList(rnd.Next(0, colorList.Count))

    ' Assign the color to the label

    Label1.BackColor = randomColour.Color
    Label1.Text = randomColour.Color.Name.ToString
    Label2.BackColor = randomColour1.Color
    Label3.BackColor = (Color.FromArgb(Label1.BackColor.ToArgb + Label2.BackColor.ToArgb))
End Sub



Aucun commentaire:

Enregistrer un commentaire