mercredi 4 mai 2016

Changing background color of a random label

I have created a 4x4 tableLayoutPanel filled with labels. I would like to change background color of one random label at a button click. I'm not sure how do I have to do it. Here is what I have so far:

    Label[,] labels = new Label[4, 4];
    Random los = new Random();
    Label pickedLabel = null;

    private void ChangeColor()
    {
        int i = los.Next(1, 4);
        int j = los.Next(1, 4);
        pickedLabel = labels[i, j];
        pickedLabel.BackColor = Color.Red;
    }




Aucun commentaire:

Enregistrer un commentaire