private void leds_Click(object sender, EventArgs e) { LEDControl led = sender as LEDControl; led.On = !led.On; if (led.Name.Equals(LED_NAME_SUFFIX + 9)) { led.IsBlink = isDance = led.On; ToggleOnOff(false); timerDance.Enabled = led.On; //data = 0; } else if (led.Name.Equals(LED_NAME_SUFFIX + 10)) { data = (led.On) ? 255 : 0; ToggleOnOff(led.On); } else { tagInt = Convert.ToInt32(led.Tag); int power = (int)Math.Pow(2, tagInt); if (led.On) { data += power; } else { data -= power; } } PortControl.Output(PORT_ADDRESS, data); ShowData(data); }
private void ToggleOnOff(bool state) { foreach (Control c in this.Controls) { if (c is LEDControl) { LEDControl led = c as LEDControl; if (isDance) { ledControl9.IsBlink = timerDance.Enabled = false; } if (!led.Tag.Equals("10")) { led.On = state; } } } }