Ejemplo n.º 1
0
        public void RefreshData()
        {
            // Create as many textboxes as fit into window
            groupBoxData.Controls.Clear();
            var x = 0;
            var y = 10;
            var z = 20;

            while (y < groupBoxData.Size.Width - 100)
            {
                var labData = new Label();
                groupBoxData.Controls.Add(labData);
                labData.Size     = new Size(40, 20);
                labData.Location = new Point(y, z);
                labData.Font     = new Font("Calibri", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0);
                switch (DisplayFormat)
                {
                case DisplayFormat.LED:
                    var bulb = new LedBulb();
                    groupBoxData.Controls.Add(bulb);
                    bulb.Size     = new Size(25, 25);
                    bulb.Location = new Point(y + 40, z - 5);
                    bulb.Padding  = new Padding(3);
                    bulb.Color    = Color.Red;
                    bulb.On       = false;
                    bulb.Tag      = x;
                    bulb.Click   += BulbClick;
                    z             = z + bulb.Size.Height + 10;
                    labData.Text  = Convert.ToString(x);
                    break;

                case DisplayFormat.Binary:
                    var txtDataB = new TextBox();
                    groupBoxData.Controls.Add(txtDataB);
                    txtDataB.Size      = new Size(110, 20);
                    txtDataB.Location  = new Point(y + 40, z - 2);
                    txtDataB.TextAlign = HorizontalAlignment.Right;
                    txtDataB.Tag       = x;
                    txtDataB.Leave    += TxtDataBinaryLeave;
                    txtDataB.Enter    += txtData_Enter;
                    txtDataB.KeyPress += txtDataBinaryKeyPress;
                    txtDataB.MaxLength = 16;
                    z            = z + txtDataB.Size.Height + 5;
                    labData.Text = Convert.ToString(StartAddress + x);
                    break;

                case DisplayFormat.Hex:
                    var txtDataH = new TextBox();
                    groupBoxData.Controls.Add(txtDataH);
                    txtDataH.Size      = new Size(55, 20);
                    txtDataH.Location  = new Point(y + 40, z - 2);
                    txtDataH.TextAlign = HorizontalAlignment.Right;
                    txtDataH.Tag       = x;
                    txtDataH.MaxLength = 5;
                    txtDataH.Leave    += TxtDataHexLeave;
                    txtDataH.Enter    += txtData_Enter;
                    txtDataH.KeyPress += txtDataHexKeyPress;
                    z            = z + txtDataH.Size.Height + 5;
                    labData.Text = Convert.ToString(StartAddress + x);
                    break;

                case DisplayFormat.Integer:
                    var txtData = new TextBox();
                    groupBoxData.Controls.Add(txtData);
                    txtData.Size      = new Size(55, 20);
                    txtData.Location  = new Point(y + 40, z - 2);
                    txtData.TextAlign = HorizontalAlignment.Right;
                    txtData.Tag       = x;
                    txtData.MaxLength = 5;
                    txtData.Leave    += TxtDataLeave;
                    txtData.Enter    += txtData_Enter;
                    txtData.KeyPress += txtDataIntegerKeyPress;
                    z            = z + txtData.Size.Height + 5;
                    labData.Text = Convert.ToString(StartAddress + x);
                    break;
                }

                x++;
                if (z > groupBoxData.Size.Height - 30)
                {
                    var inc = DisplayFormat == DisplayFormat.Binary ? 200 : 100;
                    y = y + inc;
                    z = 20;
                }
            }
            _displayCtrlCount = x;
            UpdateDataTable();
        }
Ejemplo n.º 2
0
        public void RefreshData()
        {
            // Create as many textboxes as fit into window
            groupBoxData.Visible = false;
            groupBoxData.Controls.Clear();
            var idxControl = 0;
            var screenX    = 10;
            var screenY    = 20;

            while (screenX < groupBoxData.Size.Width - 100)
            {
                var labData = new Label();
                groupBoxData.Controls.Add(labData);
                labData.Size     = new Size(40, 20);
                labData.Location = new Point(screenX, screenY);
                labData.Font     = new Font("Calibri", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0);
                switch (DisplayFormat)
                {
                case DisplayFormat.LED:
                    var bulb = new LedBulb();
                    groupBoxData.Controls.Add(bulb);
                    bulb.Size     = new Size(25, 25);
                    bulb.Location = new Point(screenX + 40, screenY - 5);
                    bulb.Padding  = new Padding(3);
                    bulb.Color    = Color.Red;
                    bulb.On       = false;
                    bulb.Tag      = idxControl;
                    bulb.Click   += BulbClick;
                    screenY       = screenY + bulb.Size.Height + 10;
                    labData.Text  = Convert.ToString(idxControl);
                    break;

                case DisplayFormat.Binary:
                    var txtDataB = new TextBox();
                    groupBoxData.Controls.Add(txtDataB);
                    txtDataB.Size      = new Size(110, 20);
                    txtDataB.Location  = new Point(screenX + 40, screenY - 2);
                    txtDataB.TextAlign = HorizontalAlignment.Right;
                    txtDataB.Tag       = idxControl;
                    txtDataB.Leave    += TxtDataBinaryLeave;
                    txtDataB.Enter    += txtData_Enter;
                    txtDataB.KeyPress += txtDataBinaryKeyPress;
                    txtDataB.MaxLength = 16;
                    screenY            = screenY + txtDataB.Size.Height + 5;
                    labData.Text       = Convert.ToString(StartAddress + idxControl);
                    break;

                case DisplayFormat.Hex:
                    var txtDataH = new TextBox();
                    groupBoxData.Controls.Add(txtDataH);
                    txtDataH.Size      = new Size(55, 20);
                    txtDataH.Location  = new Point(screenX + 40, screenY - 2);
                    txtDataH.TextAlign = HorizontalAlignment.Right;
                    txtDataH.Tag       = idxControl;
                    txtDataH.MaxLength = 5;
                    txtDataH.Leave    += TxtDataHexLeave;
                    txtDataH.Enter    += txtData_Enter;
                    txtDataH.KeyPress += txtDataHexKeyPress;
                    screenY            = screenY + txtDataH.Size.Height + 5;
                    labData.Text       = Convert.ToString(StartAddress + idxControl);
                    break;

                case DisplayFormat.Integer:
                    var txtData = new TextBox();
                    groupBoxData.Controls.Add(txtData);
                    txtData.Size      = new Size(55, 20);
                    txtData.Location  = new Point(screenX + 40, screenY - 2);
                    txtData.TextAlign = HorizontalAlignment.Right;
                    txtData.Tag       = idxControl;
                    txtData.MaxLength = 5;
                    txtData.Leave    += TxtDataLeave;
                    txtData.Enter    += txtData_Enter;
                    txtData.KeyPress += txtDataIntegerKeyPress;
                    screenY           = screenY + txtData.Size.Height + 5;
                    labData.Text      = Convert.ToString(StartAddress + idxControl);
                    break;

                case DisplayFormat.FloatReverse:
                    // Float values require two registers, thus skip every second control
                    // hide even controls
                    labData.Text = Convert.ToString(StartAddress + idxControl);
                    if ((idxControl & 1) == 0)
                    {
                        var txtFloatReverse = new TextBox();
                        groupBoxData.Controls.Add(txtFloatReverse);
                        txtFloatReverse.Size      = new Size(55, 40);
                        txtFloatReverse.Location  = new Point(screenX + 40, screenY - 2);
                        txtFloatReverse.TextAlign = HorizontalAlignment.Right;
                        txtFloatReverse.Tag       = idxControl;
                        txtFloatReverse.MaxLength = 5;
                        txtFloatReverse.Leave    += TxtFloatReverseLeave;
                        txtFloatReverse.Enter    += TxtFloatReverse_Enter;
                        txtFloatReverse.KeyPress += txtDataFloatReverseKeyPress;
                        screenY         = screenY + txtFloatReverse.Size.Height * 2 + 10; // Float Values Require Two Registers
                        labData.Visible = true;
                    }
                    else
                    {
                        labData.Visible = false;
                    }
                    break;
                }

                idxControl++;
                if (screenY > groupBoxData.Size.Height - 30)
                {
                    var inc = DisplayFormat == DisplayFormat.Binary ? 200 : 100;
                    screenX = screenX + inc;
                    screenY = 20;
                }
            }
            _displayCtrlCount = idxControl;
            UpdateDataTable();
            groupBoxData.Visible = true;
        }
Ejemplo n.º 3
0
        public void RefreshData()
        {
            // Create as many textboxes as fit into window
            groupBoxData.Controls.Clear();
            var x = 0;
            var y = 10;
            var z = 20;
            while (y < groupBoxData.Size.Width - 100)
            {
                var labData = new Label();
                groupBoxData.Controls.Add(labData);
                labData.Size = new Size(40, 20);
                labData.Location = new Point(y, z);
                labData.Font = new Font("Calibri", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0);
                switch (DisplayFormat)
                {
                    case DisplayFormat.LED:
                        var bulb = new LedBulb();
                        groupBoxData.Controls.Add(bulb);
                        bulb.Size = new Size(25, 25);
                        bulb.Location = new Point(y + 40, z - 5);
                        bulb.Padding = new Padding(3);
                        bulb.Color = Color.Red;
                        bulb.On = false;
                        bulb.Tag = x;
                        bulb.Click += BulbClick;
                        z = z + bulb.Size.Height + 10;
                        labData.Text = Convert.ToString(x);
                        break;
                    case DisplayFormat.Binary:
                        var txtDataB = new TextBox();
                        groupBoxData.Controls.Add(txtDataB);
                        txtDataB.Size = new Size(110, 20);
                        txtDataB.Location = new Point(y + 40, z - 2);
                        txtDataB.TextAlign = HorizontalAlignment.Right;
                        txtDataB.Tag = x;
                        txtDataB.Leave += TxtDataBinaryLeave;
                        txtDataB.Enter += txtData_Enter;
                        txtDataB.KeyPress += txtDataBinaryKeyPress;
                        txtDataB.MaxLength = 16;
                        z = z + txtDataB.Size.Height + 5;
                        labData.Text = Convert.ToString(StartAddress + x);
                        break;
                    case DisplayFormat.Hex:
                        var txtDataH = new TextBox();
                        groupBoxData.Controls.Add(txtDataH);
                        txtDataH.Size = new Size(55, 20);
                        txtDataH.Location = new Point(y + 40, z - 2);
                        txtDataH.TextAlign = HorizontalAlignment.Right;
                        txtDataH.Tag = x;
                        txtDataH.MaxLength = 5;
                        txtDataH.Leave += TxtDataHexLeave;
                        txtDataH.Enter += txtData_Enter;
                        txtDataH.KeyPress += txtDataHexKeyPress;
                        z = z + txtDataH.Size.Height + 5;
                        labData.Text = Convert.ToString(StartAddress + x);
                        break;
                    case DisplayFormat.Integer:
                        var txtData = new TextBox();
                        groupBoxData.Controls.Add(txtData);
                        txtData.Size = new Size(55, 20);
                        txtData.Location = new Point(y + 40, z - 2);
                        txtData.TextAlign = HorizontalAlignment.Right;
                        txtData.Tag = x;
                        txtData.MaxLength = 5;
                        txtData.Leave += TxtDataLeave;
                        txtData.Enter += txtData_Enter;
                        txtData.KeyPress += txtDataIntegerKeyPress;
                        z = z + txtData.Size.Height + 5;
                        labData.Text = Convert.ToString(StartAddress + x);
                        break;
                }

                x++;
                if (z > groupBoxData.Size.Height - 30)
                {
                    var inc = DisplayFormat == DisplayFormat.Binary ? 200 : 100;
                    y = y + inc;
                    z = 20;
                }
            }
            _displayCtrlCount = x;
            UpdateDataTable();
        }