Пример #1
0
        private void RefreshUI()
        {
            if (!hubIsTrain && Hub.IsTrain())
            {
                hubIsTrain = true;
                // Let the MainBoard know we have a new train
                PortTypeRefreshed?.Invoke();
            }

            //We clear all elements
            MainBoard.AddControlToFlowPanel(flowLayoutPanel1, null, false);
            // And rebuild the control
            InitControl();
        }
Пример #2
0
        private void InitControl()
        {
            int width = 0;

            foreach (Port p in Hub.RegistredPorts)
            {
                switch (p.Function)
                {
                case Port.Functions.MOTOR:
                case Port.Functions.TRAIN_MOTOR:
                {
                    width += 65;

                    //added by Tom Cook to increase the width to accomadate larger trackbar
                    width += 5;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_train_48;

                    Label labelSpeed = new Label();
                    labelSpeed.Text    = $"- Port {p.Id} - " + Environment.NewLine + "Speed: " + p.Speed;
                    labelSpeed.Padding = new Padding(0, 0, 0, 0);
                    labelSpeed.Width   = 60;
                    labelSpeed.Height  = 24;
                    labelSpeed.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);

                    TrackBar tb = new TrackBar();
                    tb.Width         = 50;
                    tb.Height        = 142;
                    tb.Minimum       = -100;
                    tb.Maximum       = 100;
                    tb.TickFrequency = 10;
                    tb.Orientation   = Orientation.Vertical;
                    tb.SmallChange   = 10;
                    tb.LargeChange   = 20;
                    //modified by Tom Cook for different style
                    //tb.Margin = new Padding(15, 0, 0, 0);
                    tb.Margin = new Padding(3, 0, 0, 0);
                    tb.Value  = 0;
                    //added by Tom Cook to set color to match MU function
                    tb.TickStyle = TickStyle.Both;
                    tb.BackColor = p.MUbackcolor;

                    // Connect the trackbar to the label
                    labelSpeed.Tag = tb;
                    p.label        = labelSpeed;
                    tb.Tag         = new object[] { Hub, labelSpeed, p.Id };
                    tb.Scroll     += Tb_Scrolled;

                    Button buttonStop = new Button();
                    buttonStop.Text   = "Stop";
                    buttonStop.Tag    = new object[] { Hub, p.Id };;
                    buttonStop.Click += ButtonStopTrain_Click;
                    buttonStop.Width  = 50;
                    //added by Tom Cook to pull up Stop button a little
                    buttonStop.Margin = new Padding(0, 0, 0, 0);

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelSpeed, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, tb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonStop, true);

                    break;
                }

                case Port.Functions.SWITCH_DOUBLECROSS:
                case Port.Functions.SWITCH_STANDARD:
                case Port.Functions.SWITCH_TRIXBRIX:
                {
                    width += 70;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_train_track_48;

                    Label labelSpeed = new Label();
                    labelSpeed.Text    = $"- Port {p.Id} - " + Environment.NewLine + "Pos: " + ((p.TargetSpeed == 0) ? "Unknown" : (p.TargetSpeed < 0) ? "Left" : "Right");
                    labelSpeed.Padding = new Padding(0, 0, 0, 0);
                    labelSpeed.Width   = 60;
                    labelSpeed.Height  = 24;
                    labelSpeed.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);
                    p.label            = labelSpeed;

                    Button buttonLeft = new Button();
                    buttonLeft.Text   = "Left";
                    buttonLeft.Tag    = new object[] { Hub, p.Id, -100 };;
                    buttonLeft.Click += ButtonActivateSwitch_Click;
                    buttonLeft.Width  = 50;
                    //added by Tom Cook to offset button
                    buttonLeft.Padding = new Padding(0, 0, 15, 0);
                    //added by Tom Cook for MU function
                    buttonLeft.BackColor = p.MUbackcolor;
                    if (p.MUbackcolor == Color.Black ||
                        p.MUbackcolor == Color.Blue ||
                        p.MUbackcolor == Color.Purple ||
                        p.MUbackcolor == Color.Green ||
                        p.MUbackcolor == Color.Red
                        )
                    {
                        buttonLeft.ForeColor = Color.White;
                    }

                    Button buttonRight = new Button();
                    buttonRight.Text   = "Right";
                    buttonRight.Tag    = new object[] { Hub, p.Id, 100 };;
                    buttonRight.Click += ButtonActivateSwitch_Click;
                    buttonRight.Width  = 50;
                    //added by Tom Cook to offset button
                    buttonRight.Padding = new Padding(10, 0, 0, 0);
                    //added by Tom Cook for MU function
                    buttonRight.BackColor = p.MUbackcolor;
                    if (p.MUbackcolor == Color.Black ||
                        p.MUbackcolor == Color.Blue ||
                        p.MUbackcolor == Color.Purple ||
                        p.MUbackcolor == Color.Green ||
                        p.MUbackcolor == Color.Red
                        )
                    {
                        buttonRight.ForeColor = Color.White;
                    }

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelSpeed, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonLeft, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonRight, true);

                    break;
                }

                case Port.Functions.SENSOR:
                {
                    width += 70;

                    //added by Tom Cook to widen for COLOR name
                    width += 10;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_motion_sensor_48;

                    Label labelColor = new Label();
                    labelColor.Text = $"- Port {p.Id} - " + Environment.NewLine + "Color:" + Enum.GetName(typeof(Port.Colors), p.LatestColor) + Environment.NewLine + "Distance: 0";
                    labelColor.Font = new Font(new FontFamily("Segoe UI"), 7.1f);

                    labelColor.Padding = new Padding(0, 0, 0, 0);
                    labelColor.Width   = 71;

                    //modified by Tom Cook to format more data in box
                    //labelColor.Height = 80;
                    labelColor.Height = 47;

                    // Connect the trackbar to the label
                    p.label = labelColor;

                    //added by Tom Cook to add 'Black' buton
                    Button buttonBlack = new Button();
                    buttonBlack.Text   = "Off";
                    buttonBlack.Tag    = new object[] { Hub, p.Id, Color.Black };;
                    buttonBlack.Click += ButtonColor_Click;
                    buttonBlack.Width  = 50;
                    //buttonBlack.Visible = Hub.Type != Hub.Types.WEDO_2_SMART_HUB;

                    //added by Tom Cook to add 'Blue' button
                    Button buttonBlue = new Button();
                    buttonBlue.Text   = "Blue";
                    buttonBlue.Tag    = new object[] { Hub, p.Id, Color.Blue };;
                    buttonBlue.Click += ButtonColor_Click;
                    buttonBlue.Width  = 50;
                    //buttonBlue.Visible = Hub.Type != Hub.Types.WEDO_2_SMART_HUB;

                    //added by Tom Cook to add 'Green' button
                    Button buttonGreen = new Button();
                    buttonGreen.Text   = "Green";
                    buttonGreen.Tag    = new object[] { Hub, p.Id, Color.Green };;
                    buttonGreen.Click += ButtonColor_Click;
                    buttonGreen.Width  = 50;
                    //buttonGreen.Visible = Hub.Type != Hub.Types.WEDO_2_SMART_HUB;

                    //added by Tom Cook to add 'Red' button
                    Button buttonRed = new Button();
                    buttonRed.Text   = "Red";
                    buttonRed.Tag    = new object[] { Hub, p.Id, Color.Red };;
                    buttonRed.Click += ButtonColor_Click;
                    buttonRed.Width  = 50;
                    //buttonRed.Visible = Hub.Type != Hub.Types.WEDO_2_SMART_HUB;

                    //added by Tom Cook to add 'White' button
                    Button buttonWhite = new Button();
                    buttonWhite.Text   = "White";
                    buttonWhite.Tag    = new object[] { Hub, p.Id, Color.White };;
                    buttonWhite.Click += ButtonColor_Click;
                    buttonWhite.Width  = 50;
                    //buttonWhite.Visible = Hub.Type != Hub.Types.WEDO_2_SMART_HUB;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    //modified by Tom Cook to change 'true' to 'false' so could add buttons then enter 'true'
                    //MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelColor, true);

                    //added by Tom Cook, see above - 'true' for end of column of elements
                    if (p.Device == Port.Devices.BOOST_DISTANCE && Hub.Type != Hub.Types.WEDO_2_SMART_HUB)
                    {
                        MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelColor, false);
                        MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonBlack, false);
                        MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonBlue, false);
                        MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonGreen, false);
                        MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonRed, false);
                        MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonWhite, true);
                    }
                    else
                    {
                        MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelColor, true);
                    }


                    break;
                }

                case Port.Functions.LIGHT:
                {
                    width += 70;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_light_48;

                    Label labelLight = new Label();
                    labelLight.Text    = $"- Port {p.Id} - " + Environment.NewLine + "Light is " + ((p.TargetSpeed == 0) ? "Off" : "On");
                    labelLight.Padding = new Padding(0, 0, 0, 0);
                    labelLight.Width   = 60;
                    labelLight.Height  = 36;
                    labelLight.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);

                    // Connect the trackbar to the label
                    p.label = labelLight;

                    Button buttonOn = new Button();
                    buttonOn.Text   = "On";
                    buttonOn.Tag    = new object[] { Hub, p.Id, 100 };;
                    buttonOn.Click += ButtonOnOff_Click;
                    buttonOn.Width  = 50;

                    //added by Tom Cook for 'Bright' button
                    Button buttonBright = new Button();
                    buttonBright.Text   = "Bright";
                    buttonBright.Tag    = new object[] { Hub, p.Id, 80 };;
                    buttonBright.Click += ButtonOnOff_Click;
                    buttonBright.Width  = 50;

                    //added by Tom Cook for 'Normal' button
                    Button buttonNormal = new Button();
                    buttonNormal.Text   = "Normal";
                    buttonNormal.Tag    = new object[] { Hub, p.Id, 50 };;
                    buttonNormal.Click += ButtonOnOff_Click;
                    buttonNormal.Width  = 50;

                    //added by Tom Cook for 'Dim' button
                    Button buttonDim = new Button();
                    buttonDim.Text   = "Dim";
                    buttonDim.Tag    = new object[] { Hub, p.Id, 20 };;
                    buttonDim.Click += ButtonOnOff_Click;
                    buttonDim.Width  = 50;

                    Button buttonOff = new Button();
                    buttonOff.Text   = "Off";
                    buttonOff.Tag    = new object[] { Hub, p.Id, 0 };;
                    buttonOff.Click += ButtonOnOff_Click;
                    buttonOff.Width  = 50;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelLight, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonOn, false);

                    //added by Tom Cook add button and make last button 'true' for end of column of elements
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonBright, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonNormal, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonDim, false);

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonOff, true);

                    break;
                }

                case Port.Functions.BUTTON:
                {
                    width += 75;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(15, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = (p.Id == "A") ? Properties.Resources.icons8_xbox_a_48 : Properties.Resources.icons8_xbox_b_48;

                    Label labelLight = new Label();
                    labelLight.Text    = $"  - Port {p.Id} - " + Environment.NewLine + ((p.Id == "A") ? "Left Buttons" : "Right Buttons");
                    labelLight.Padding = new Padding(0, 0, 0, 0);
                    labelLight.Width   = 65;
                    labelLight.Height  = 36;
                    labelLight.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelLight, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, true);

                    break;
                }

                case Port.Functions.PFX_SPEAKER:
                {
                    width += 100;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_speaker_48;

                    Label labelLight = new Label();
                    labelLight.Text    = $"  - Port {p.Id} - " + Environment.NewLine + "PFx - Speaker";
                    labelLight.Padding = new Padding(0, 0, 0, 0);
                    labelLight.Width   = 75;
                    labelLight.Height  = 36;
                    labelLight.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);


                    ComboBox comboFiles = new ComboBox();
                    comboFiles.Width         = 65;
                    comboFiles.DropDownWidth = 100;
                    comboFiles.DropDownStyle = ComboBoxStyle.DropDownList;

                    for (int i = 0; i < 64; i++)
                    {
                        comboFiles.Items.Add("File id " + i);
                    }

                    Button buttonPlay = new Button();
                    buttonPlay.Text   = "Play";
                    buttonPlay.Tag    = comboFiles;
                    buttonPlay.Click += ButtonPlay_Click;;
                    buttonPlay.Width  = 50;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelLight, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, comboFiles, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonPlay, true);

                    break;
                }

                case Port.Functions.PFX_LIGHT_CONTROLER:
                {
                    width += 150;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_light_automation_48;

                    Label labelLight = new Label();
                    labelLight.Text    = $"  - Port {p.Id} - " + Environment.NewLine + "PFx - 8x Light Hub";
                    labelLight.Padding = new Padding(0, 0, 0, 0);
                    labelLight.Width   = 95;
                    labelLight.Height  = 36;
                    labelLight.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);

                    ComboBox comboFiles = new ComboBox();
                    comboFiles.Width         = 135;
                    comboFiles.DropDownWidth = 170;
                    comboFiles.DropDownStyle = ComboBoxStyle.DropDownList;

                    foreach (PFxLightFx fx in Enum.GetValues(typeof(PFxLightFx)))
                    {
                        comboFiles.Items.Add(fx.ToString());
                    }

                    Button buttonPlay = new Button();
                    buttonPlay.Text   = "Test Light";
                    buttonPlay.Tag    = comboFiles;
                    buttonPlay.Click += ButtonPlayLight_Click;
                    buttonPlay.Width  = 50;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelLight, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, comboFiles, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonPlay, true);

                    break;
                }
                }
            }

            //modified by Tom Cook to increase width to show Volts and mAmps even when no devices attached to hub
            //MainBoard.SetControlPropertyThreadSafe(this, "Width", (width < 110) ? 110 : width);
            MainBoard.SetControlPropertyThreadSafe(this, "Width", (width < 140) ? 140 : width);
        }
Пример #3
0
        private void InitControl()
        {
            int width = 0;

            foreach (Port p in Hub.RegistredPorts)
            {
                switch (p.Function)
                {
                case Port.Functions.MOTOR:
                case Port.Functions.TRAIN_MOTOR:
                {
                    width += 65;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_train_48;

                    Label labelSpeed = new Label();
                    labelSpeed.Text    = $"- Port {p.Id} - " + Environment.NewLine + "Speed: " + p.Speed;
                    labelSpeed.Padding = new Padding(0, 0, 0, 0);
                    labelSpeed.Width   = 60;
                    labelSpeed.Height  = 24;
                    labelSpeed.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);

                    TrackBar tb = new TrackBar();
                    tb.Width         = 50;
                    tb.Height        = 100;
                    tb.Minimum       = -100;
                    tb.Maximum       = 100;
                    tb.TickFrequency = 10;
                    tb.Orientation   = Orientation.Vertical;
                    tb.SmallChange   = 10;
                    tb.LargeChange   = 20;
                    tb.Margin        = new Padding(15, 0, 0, 0);
                    tb.Value         = 0;

                    // Connect the trackbar to the label
                    labelSpeed.Tag = tb;
                    p.label        = labelSpeed;

                    tb.Tag     = new object[] { Hub, labelSpeed, p.Id };
                    tb.Scroll += Tb_Scrolled;

                    Button buttonStop = new Button();
                    buttonStop.Text   = "Stop";
                    buttonStop.Tag    = new object[] { Hub, p.Id };;
                    buttonStop.Click += ButtonStopTrain_Click;
                    buttonStop.Width  = 50;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelSpeed, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, tb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonStop, true);

                    break;
                }

                case Port.Functions.SWITCH_DOUBLECROSS:
                case Port.Functions.SWITCH_STANDARD:
                case Port.Functions.SWITCH_TRIXBRIX:
                {
                    width += 70;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_train_track_48;

                    Label labelSpeed = new Label();
                    labelSpeed.Text    = $"- Port {p.Id} - " + Environment.NewLine + "Pos: " + ((p.TargetSpeed == 0) ? "Unknown" : (p.TargetSpeed < 0) ? "Left" : "Right");
                    labelSpeed.Padding = new Padding(0, 0, 0, 0);
                    labelSpeed.Width   = 60;
                    labelSpeed.Height  = 24;
                    labelSpeed.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);
                    p.label            = labelSpeed;

                    Button buttonLeft = new Button();
                    buttonLeft.Text   = "Left";
                    buttonLeft.Tag    = new object[] { Hub, p.Id, -100 };;
                    buttonLeft.Click += ButtonActivateSwitch_Click;
                    buttonLeft.Width  = 50;

                    Button buttonRight = new Button();
                    buttonRight.Text   = "Right";
                    buttonRight.Tag    = new object[] { Hub, p.Id, 100 };;
                    buttonRight.Click += ButtonActivateSwitch_Click;
                    buttonRight.Width  = 50;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelSpeed, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonLeft, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonRight, true);

                    break;
                }

                case Port.Functions.SENSOR:
                {
                    width += 70;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_motion_sensor_48;

                    Label labelColor = new Label();
                    labelColor.Text = $"- Port {p.Id} - " + Environment.NewLine + "Color:" + Enum.GetName(typeof(Port.Colors), p.LatestColor) + Environment.NewLine + "Distance: 0";
                    labelColor.Font = new Font(new FontFamily("Segoe UI"), 7.1f);

                    labelColor.Padding = new Padding(0, 0, 0, 0);
                    labelColor.Width   = 65;
                    labelColor.Height  = 80;

                    // Connect the trackbar to the label
                    p.label = labelColor;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelColor, true);

                    break;
                }

                case Port.Functions.LIGHT:
                {
                    width += 70;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_light_48;

                    Label labelLight = new Label();
                    labelLight.Text    = $"- Port {p.Id} - " + Environment.NewLine + "Light is " + ((p.TargetSpeed == 0) ? "Off" : "On");
                    labelLight.Padding = new Padding(0, 0, 0, 0);
                    labelLight.Width   = 60;
                    labelLight.Height  = 36;
                    labelLight.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);

                    // Connect the trackbar to the label
                    p.label = labelLight;

                    Button buttonOn = new Button();
                    buttonOn.Text   = "On";
                    buttonOn.Tag    = new object[] { Hub, p.Id, 100 };;
                    buttonOn.Click += ButtonOnOff_Click;
                    buttonOn.Width  = 50;

                    Button buttonOff = new Button();
                    buttonOff.Text   = "Off";
                    buttonOff.Tag    = new object[] { Hub, p.Id, 0 };;
                    buttonOff.Click += ButtonOnOff_Click;
                    buttonOff.Width  = 50;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelLight, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonOn, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonOff, true);

                    break;
                }

                case Port.Functions.BUTTON:
                {
                    width += 75;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(15, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = (p.Id == "A") ? Properties.Resources.icons8_xbox_a_48 : Properties.Resources.icons8_xbox_b_48;

                    Label labelLight = new Label();
                    labelLight.Text    = $"  - Port {p.Id} - " + Environment.NewLine + ((p.Id == "A") ? "Left Buttons" : "Right Buttons");
                    labelLight.Padding = new Padding(0, 0, 0, 0);
                    labelLight.Width   = 65;
                    labelLight.Height  = 36;
                    labelLight.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelLight, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, true);

                    break;
                }

                case Port.Functions.PFX_SPEAKER:
                {
                    width += 100;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_speaker_48;

                    Label labelLight = new Label();
                    labelLight.Text    = $"  - Port {p.Id} - " + Environment.NewLine + "PFx - Speaker";
                    labelLight.Padding = new Padding(0, 0, 0, 0);
                    labelLight.Width   = 75;
                    labelLight.Height  = 36;
                    labelLight.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);


                    ComboBox comboFiles = new ComboBox();
                    comboFiles.Width         = 65;
                    comboFiles.DropDownWidth = 100;
                    comboFiles.DropDownStyle = ComboBoxStyle.DropDownList;

                    for (int i = 0; i < 64; i++)
                    {
                        comboFiles.Items.Add("File id " + i);
                    }

                    Button buttonPlay = new Button();
                    buttonPlay.Text   = "Play";
                    buttonPlay.Tag    = comboFiles;
                    buttonPlay.Click += ButtonPlay_Click;;
                    buttonPlay.Width  = 50;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelLight, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, comboFiles, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonPlay, true);

                    break;
                }

                case Port.Functions.PFX_LIGHT_CONTROLER:
                {
                    width += 150;

                    PictureBox pb = new PictureBox();
                    pb.Width    = 30;
                    pb.Height   = 30;
                    pb.Margin   = new Padding(10, 0, 0, 0);
                    pb.SizeMode = PictureBoxSizeMode.StretchImage;
                    pb.Image    = Properties.Resources.icons8_light_automation_48;

                    Label labelLight = new Label();
                    labelLight.Text    = $"  - Port {p.Id} - " + Environment.NewLine + "PFx - 8x Light Hub";
                    labelLight.Padding = new Padding(0, 0, 0, 0);
                    labelLight.Width   = 95;
                    labelLight.Height  = 36;
                    labelLight.Font    = new Font(new FontFamily("Segoe UI"), 7.1f);

                    ComboBox comboFiles = new ComboBox();
                    comboFiles.Width         = 135;
                    comboFiles.DropDownWidth = 170;
                    comboFiles.DropDownStyle = ComboBoxStyle.DropDownList;

                    foreach (PFxLightFx fx in Enum.GetValues(typeof(PFxLightFx)))
                    {
                        comboFiles.Items.Add(fx.ToString());
                    }

                    Button buttonPlay = new Button();
                    buttonPlay.Text   = "Test Light";
                    buttonPlay.Tag    = comboFiles;
                    buttonPlay.Click += ButtonPlayLight_Click;
                    buttonPlay.Width  = 50;

                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, pb, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, labelLight, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, comboFiles, false);
                    MainBoard.AddControlToFlowPanel(flowLayoutPanel1, buttonPlay, true);

                    break;
                }
                }
            }

            MainBoard.SetControlPropertyThreadSafe(this, "Width", (width < 110) ? 110 : width);
        }