mercredi 27 juillet 2016

Processing one char at a time within a string in a foreach loop

I have a string that storages a sequence of numbers. Then I split in chars using foreach, send the info to highlightButton()and using a dictionary he does some actions. The problem is that it is processing all the chars at once but I'd like it to process it one char at a time: He's changing all backgrounds at once; i'd like it to be one at a time, in order. Perhaps using a timer? Code below

  Random rng = new Random();
  sequence = sequence + rng.Next(1, 5);

  foreach (char c in sequence)
        {
            highlightButton(charToButton[c]);
        }

private void highlightButton(Button button)
    {
        Dictionary<Button, PictureBox> buttonToPB = new Dictionary<Button, PictureBox>();
        //4 buttons
        buttonToPB.Add(bRED, pbRED);
        buttonToPB.Add(bYELLOW, pbYELLOW);
        buttonToPB.Add(bGREEN, pbGREEN);
        buttonToPB.Add(bBLUE, pbBLUE);

        buttonToPB[button].BackColor = Color.Black;
    }




Aucun commentaire:

Enregistrer un commentaire