mardi 22 novembre 2016

Omitting the selection of checkboxes

So I have a drum machine with a random button that fills every checkbox randomly. I want no 2 drums to play at the same time. There are 16 beats, with 5 drums total. So I'm thinking of using a for loop that examines the current value in the list, then set the checkbox boolean to false for values plus or minus 16.

For example: if checkbox 1 is selected, checkboxes 17, 33, 49, and 65 should be empty. Likewise if checkbox 56 is selected, 8, 24, 40, and 72 should be unchecked. The same should go for every checkbox. I'm not sure how to do this.

Here is the code for randomly filling the checkboxes:

private void randombuttonClick(object sender, EventArgs e)
        {
            List<CheckBox> Checkboxlist = new List<CheckBox>();
            foreach (CheckBox control in this.Controls.OfType<CheckBox>())
            {
                Checkboxlist.Add(control);
                control.Checked = false;
            }

            for (int i = 0; i <= 50; i++)
            {
                var r = random.Next(0, Checkboxlist.Count);
                var checkbox = Checkboxlist[r];
                Checkboxlist[r].Checked = true;
            }
        }

Thanks for looking!




Aucun commentaire:

Enregistrer un commentaire