Пример #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            LEDButton[,] b = new LEDButton[4, 4];
            for (int y = 0; y < b.GetUpperBound(0); y++)
            {
                for (int x = 0; x < b.GetUpperBound(1); x++)
                {
                    b[y, x] = new LEDButton()
                    {
                        //put button properties here
                        Name     = "button" + y.ToString() + x.ToString(),//String.Format("Button{0}{1}", y, x),
                        TabIndex = 10 * y + x,
                        Text     = y.ToString() + x.ToString(),
                        Location = new Point(LEDButton.LEDWidth * x + 20, LEDButton.LEDHeight * y + 20)
                    };

                    if (y <= 3)
                    {
                        b[y, x].Click += new System.EventHandler(clickMethods[y]);
                    }
                }
            }
            // add buttons to controls
            for (int y = 0; y < b.GetUpperBound(0); y++)
            {
                for (int x = 0; x < b.GetUpperBound(1); x++)
                {
                    this.Controls.Add(b[y, x]);
                }
            }
        }
Пример #2
0
        private void InBit_Click(object sender, EventArgs e)
        {
            LEDButton led = sender as LEDButton;

            if (led == null || led.ReadOnly)
            {
                return;
            }

            int bitNum = Convert.ToInt32(led.Tag) + _bitGroup * NUM_IO_DISPLAY;

            if (bitNum >= _io.DIBits.Count)
            {
                return;
            }

            DIBit bit = _io.DIBits[bitNum];

            if (bit == null)
            {
                return;
            }

            bool prevState = led.Checked;

            led.Enabled = false;

            Task.Factory.StartNew <bool>(() =>
            {
                // toggle the value
                bool value = !bit.Get();
                bit.Set(value);
                return(value);
            })
            .ContinueWith(t =>
            {
                UIUtility.BeginInvoke(this, () =>
                {
                    led.Checked = t.Result;
                    led.Enabled = true;
                });

                if (t.IsFaulted)
                {
                    Notify.PopUpError(String.Format("Failed to Set {0}", bit.Name), t.Exception.InnerException);
                }
            });
        }