public EditConnectionWidget(ConnectionWindow windowController, GuiWidget containerWindowToClose, Printer activePrinter = null, object state = null)
			: base(windowController, containerWindowToClose)
		{
			textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.borderWidth = 0;

			linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
			linkButtonFactory.fontSize = 8;

			this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
			this.AnchorAll();
			this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off

			GuiWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
			mainContainer.AnchorAll();
			mainContainer.Padding = new BorderDouble(3, 3, 3, 5);
			mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			string headerTitle;

			if (activePrinter == null)
			{
				headerTitle = string.Format("Add a Printer");
				this.addNewPrinterFlag = true;
				this.ActivePrinter = new Printer();
				this.ActivePrinter.Name = "Default Printer";
				this.ActivePrinter.BaudRate = "250000";
				try
				{
					this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault();
				}
				catch(Exception e)
				{
					Debug.Print(e.Message);
					GuiWidget.BreakInDebugger();
					//No active COM ports
				}
			}
			else
			{
				this.ActivePrinter = activePrinter;
				string editHeaderTitleTxt = LocalizedString.Get("Edit");
				headerTitle = string.Format("{1} - {0}", this.ActivePrinter.Name, editHeaderTitleTxt);
				if (this.ActivePrinter.BaudRate == null)
				{
					this.ActivePrinter.BaudRate = "250000";
				}
				if (this.ActivePrinter.ComPort == null)
				{
					try
					{
						this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault();
					}
					catch(Exception e)
					{
						Debug.Print(e.Message);
						GuiWidget.BreakInDebugger();
						//No active COM ports
					}
				}
			}

			FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
			headerRow.Margin = new BorderDouble(0, 3, 0, 0);
			headerRow.Padding = new BorderDouble(0, 3, 0, 3);
			headerRow.HAnchor = HAnchor.ParentLeftRight;
			{
				TextWidget headerLabel = new TextWidget(headerTitle, pointSize: 14);
				headerLabel.TextColor = this.defaultTextColor;

				headerRow.AddChild(headerLabel);
			}

			ConnectionControlContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
			ConnectionControlContainer.Padding = new BorderDouble(5);
			ConnectionControlContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
			ConnectionControlContainer.HAnchor = HAnchor.ParentLeftRight;
			{
				TextWidget printerNameLabel = new TextWidget(LocalizedString.Get("Printer Name"), 0, 0, 10);
				printerNameLabel.TextColor = this.defaultTextColor;
				printerNameLabel.HAnchor = HAnchor.ParentLeftRight;
				printerNameLabel.Margin = new BorderDouble(0, 0, 0, 1);

				printerNameInput = new MHTextEditWidget(this.ActivePrinter.Name);

				printerNameInput.HAnchor |= HAnchor.ParentLeftRight;

				comPortLabelWidget = new FlowLayoutWidget();

				Button refreshComPorts = linkButtonFactory.Generate(LocalizedString.Get("(refresh)"));
				refreshComPorts.Margin = new BorderDouble(left: 5);
				refreshComPorts.VAnchor = VAnchor.ParentBottom;
				refreshComPorts.Click += new EventHandler(RefreshComPorts);

				FlowLayoutWidget comPortContainer = null;

#if !__ANDROID__
				TextWidget comPortLabel = new TextWidget(LocalizedString.Get("Serial Port"), 0, 0, 10);
				comPortLabel.TextColor = this.defaultTextColor;

				comPortLabelWidget.AddChild(comPortLabel);
				comPortLabelWidget.AddChild(refreshComPorts);
				comPortLabelWidget.Margin = new BorderDouble(0, 0, 0, 10);
				comPortLabelWidget.HAnchor = HAnchor.ParentLeftRight;

				comPortContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
				comPortContainer.Margin = new BorderDouble(0);
				comPortContainer.HAnchor = HAnchor.ParentLeftRight;

				CreateSerialPortControls(comPortContainer, this.ActivePrinter.ComPort);
#endif

				TextWidget baudRateLabel = new TextWidget(LocalizedString.Get("Baud Rate"), 0, 0, 10);
				baudRateLabel.TextColor = this.defaultTextColor;
				baudRateLabel.Margin = new BorderDouble(0, 0, 0, 10);
				baudRateLabel.HAnchor = HAnchor.ParentLeftRight;

				baudRateWidget = GetBaudRateWidget();
				baudRateWidget.HAnchor = HAnchor.ParentLeftRight;

				FlowLayoutWidget printerMakeContainer = createPrinterMakeContainer();
				FlowLayoutWidget printerModelContainer = createPrinterModelContainer();

				enableAutoconnect = new CheckBox(LocalizedString.Get("Auto Connect"));
				enableAutoconnect.TextColor = ActiveTheme.Instance.PrimaryTextColor;
				enableAutoconnect.Margin = new BorderDouble(top: 10);
				enableAutoconnect.HAnchor = HAnchor.ParentLeft;
				if (this.ActivePrinter.AutoConnectFlag)
				{
					enableAutoconnect.Checked = true;
				}

				if (state as StateBeforeRefresh != null)
				{
					enableAutoconnect.Checked = ((StateBeforeRefresh)state).autoConnect;
				}

				SerialPortControl serialPortScroll = new SerialPortControl();

				if (comPortContainer != null)
				{
					serialPortScroll.AddChild(comPortContainer);
				}

				ConnectionControlContainer.VAnchor = VAnchor.ParentBottomTop;
				ConnectionControlContainer.AddChild(printerNameLabel);
				ConnectionControlContainer.AddChild(printerNameInput);
				ConnectionControlContainer.AddChild(printerMakeContainer);
				ConnectionControlContainer.AddChild(printerModelContainer);
				ConnectionControlContainer.AddChild(comPortLabelWidget);
				ConnectionControlContainer.AddChild(serialPortScroll);
				ConnectionControlContainer.AddChild(baudRateLabel);
				ConnectionControlContainer.AddChild(baudRateWidget);
#if !__ANDROID__
				ConnectionControlContainer.AddChild(enableAutoconnect);
#endif
			}

			FlowLayoutWidget buttonContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
			buttonContainer.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight;
			//buttonContainer.VAnchor = VAnchor.BottomTop;
			buttonContainer.Margin = new BorderDouble(0, 5, 0, 3);
			{
				//Construct buttons
				saveButton = textImageButtonFactory.Generate(LocalizedString.Get("Save"));
				//saveButton.VAnchor = VAnchor.Bottom;

				cancelButton = textImageButtonFactory.Generate(LocalizedString.Get("Cancel"));
				//cancelButton.VAnchor = VAnchor.Bottom;
				cancelButton.Click += new EventHandler(CancelButton_Click);

				//Add buttons to buttonContainer
				buttonContainer.AddChild(saveButton);
				buttonContainer.AddChild(new HorizontalSpacer());
				buttonContainer.AddChild(cancelButton);
			}

			//mainContainer.AddChild(new PrinterChooser());

			mainContainer.AddChild(headerRow);
			mainContainer.AddChild(ConnectionControlContainer);
			mainContainer.AddChild(buttonContainer);

			this.AddChild(mainContainer);

			BindSaveButtonHandlers();
			BindBaudRateHandlers();
		}
        public EditConnectionWidget(ConnectionWindow windowController, GuiWidget containerWindowToClose, Printer activePrinter = null, object state = null)
            : base(windowController, containerWindowToClose)
        {
            textImageButtonFactory.normalTextColor   = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.hoverTextColor    = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.pressedTextColor  = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.borderWidth       = 0;

            linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
            linkButtonFactory.fontSize  = 8;

            this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            this.AnchorAll();
            this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off

            GuiWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            mainContainer.AnchorAll();
            mainContainer.Padding         = new BorderDouble(3, 3, 3, 5);
            mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

            string headerTitle;

            if (activePrinter == null)
            {
                headerTitle                 = string.Format("Add a Printer");
                this.addNewPrinterFlag      = true;
                this.ActivePrinter          = new Printer();
                this.ActivePrinter.Name     = "Default Printer";
                this.ActivePrinter.BaudRate = "250000";
                try
                {
                    this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault();
                }
                catch
                {
                    //No active COM ports
                }
            }
            else
            {
                this.ActivePrinter = activePrinter;
                string editHeaderTitleTxt = LocalizedString.Get("Edit");
                headerTitle = string.Format("{1} - {0}", this.ActivePrinter.Name, editHeaderTitleTxt);
                if (this.ActivePrinter.BaudRate == null)
                {
                    this.ActivePrinter.BaudRate = "250000";
                }
                if (this.ActivePrinter.ComPort == null)
                {
                    try
                    {
                        this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault();
                    }
                    catch
                    {
                        //No active COM ports
                    }
                }
            }

            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);

            headerRow.Margin  = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);
            headerRow.HAnchor = HAnchor.ParentLeftRight;
            {
                TextWidget headerLabel = new TextWidget(headerTitle, pointSize: 14);
                headerLabel.TextColor = this.defaultTextColor;

                headerRow.AddChild(headerLabel);
            }

            ConnectionControlContainer                 = new FlowLayoutWidget(FlowDirection.TopToBottom);
            ConnectionControlContainer.Padding         = new BorderDouble(5);
            ConnectionControlContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            ConnectionControlContainer.HAnchor         = HAnchor.ParentLeftRight;
            {
                TextWidget printerNameLabel = new TextWidget(LocalizedString.Get("Printer Name"), 0, 0, 10);
                printerNameLabel.TextColor = this.defaultTextColor;
                printerNameLabel.HAnchor   = HAnchor.ParentLeftRight;
                printerNameLabel.Margin    = new BorderDouble(0, 0, 0, 1);

                printerNameInput = new MHTextEditWidget(this.ActivePrinter.Name);

                printerNameInput.HAnchor |= HAnchor.ParentLeftRight;

                comPortLabelWidget = new FlowLayoutWidget();

                Button refreshComPorts = linkButtonFactory.Generate(LocalizedString.Get("(refresh)"));
                refreshComPorts.Margin  = new BorderDouble(left: 5);
                refreshComPorts.VAnchor = VAnchor.ParentBottom;
                refreshComPorts.Click  += new EventHandler(RefreshComPorts);

                FlowLayoutWidget comPortContainer = null;

#if !__ANDROID__
                TextWidget comPortLabel = new TextWidget(LocalizedString.Get("Serial Port"), 0, 0, 10);
                comPortLabel.TextColor = this.defaultTextColor;

                comPortLabelWidget.AddChild(comPortLabel);
                comPortLabelWidget.AddChild(refreshComPorts);
                comPortLabelWidget.Margin  = new BorderDouble(0, 0, 0, 10);
                comPortLabelWidget.HAnchor = HAnchor.ParentLeftRight;

                comPortContainer         = new FlowLayoutWidget(FlowDirection.TopToBottom);
                comPortContainer.Margin  = new BorderDouble(0);
                comPortContainer.HAnchor = HAnchor.ParentLeftRight;


                int portIndex = 0;
                foreach (string serialPort in FrostedSerialPort.GetPortNames())
                {
                    //Filter com port list based on usb type (applies to Mac mostly)
                    bool looks_like_mac = serialPort.StartsWith("/dev/tty.");
                    bool looks_like_pc  = serialPort.StartsWith("COM");
                    if (looks_like_mac || looks_like_pc)
                    {
                        SerialPortIndexRadioButton comPortOption = createComPortOption(serialPort);
                        comPortContainer.AddChild(comPortOption);
                        portIndex++;
                    }
                }

                //If there are no com ports in the filtered list assume we are missing something and show the unfiltered list
                if (portIndex == 0)
                {
                    foreach (string serialPort in FrostedSerialPort.GetPortNames())
                    {
                        SerialPortIndexRadioButton comPortOption = createComPortOption(serialPort);
                        comPortContainer.AddChild(comPortOption);
                        portIndex++;
                    }
                }

                if (!printerComPortIsAvailable && this.ActivePrinter.ComPort != null)
                {
                    SerialPortIndexRadioButton comPortOption = createComPortOption(this.ActivePrinter.ComPort);
                    comPortOption.Enabled = false;
                    comPortContainer.AddChild(comPortOption);
                    portIndex++;
                }

                //If there are still no com ports show a message to that effect
                if (portIndex == 0)
                {
                    TextWidget comPortOption = new TextWidget(LocalizedString.Get("No COM ports available"));
                    comPortOption.Margin    = new BorderDouble(3, 6, 5, 6);
                    comPortOption.TextColor = this.subContainerTextColor;
                    comPortContainer.AddChild(comPortOption);
                }
#endif

                TextWidget baudRateLabel = new TextWidget(LocalizedString.Get("Baud Rate"), 0, 0, 10);
                baudRateLabel.TextColor = this.defaultTextColor;
                baudRateLabel.Margin    = new BorderDouble(0, 0, 0, 10);
                baudRateLabel.HAnchor   = HAnchor.ParentLeftRight;

                baudRateWidget         = GetBaudRateWidget();
                baudRateWidget.HAnchor = HAnchor.ParentLeftRight;

                FlowLayoutWidget printerMakeContainer  = createPrinterMakeContainer();
                FlowLayoutWidget printerModelContainer = createPrinterModelContainer();

                enableAutoconnect           = new CheckBox(LocalizedString.Get("Auto Connect"));
                enableAutoconnect.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                enableAutoconnect.Margin    = new BorderDouble(top: 10);
                enableAutoconnect.HAnchor   = HAnchor.ParentLeft;
                if (this.ActivePrinter.AutoConnectFlag)
                {
                    enableAutoconnect.Checked = true;
                }

                if (state as StateBeforeRefresh != null)
                {
                    enableAutoconnect.Checked = ((StateBeforeRefresh)state).autoConnect;
                }

                SerialPortControl serialPortScroll = new SerialPortControl();

                if (comPortContainer != null)
                {
                    serialPortScroll.AddChild(comPortContainer);
                }

                ConnectionControlContainer.VAnchor = VAnchor.ParentBottomTop;
                ConnectionControlContainer.AddChild(printerNameLabel);
                ConnectionControlContainer.AddChild(printerNameInput);
                ConnectionControlContainer.AddChild(printerMakeContainer);
                ConnectionControlContainer.AddChild(printerModelContainer);
                ConnectionControlContainer.AddChild(comPortLabelWidget);
                ConnectionControlContainer.AddChild(serialPortScroll);
                ConnectionControlContainer.AddChild(baudRateLabel);
                ConnectionControlContainer.AddChild(baudRateWidget);
#if !__ANDROID__
                ConnectionControlContainer.AddChild(enableAutoconnect);
#endif
            }

            FlowLayoutWidget buttonContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
            buttonContainer.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight;
            //buttonContainer.VAnchor = VAnchor.BottomTop;
            buttonContainer.Margin = new BorderDouble(0, 5, 0, 3);
            {
                //Construct buttons
                saveButton = textImageButtonFactory.Generate(LocalizedString.Get("Save"));
                //saveButton.VAnchor = VAnchor.Bottom;



                cancelButton = textImageButtonFactory.Generate(LocalizedString.Get("Cancel"));
                //cancelButton.VAnchor = VAnchor.Bottom;
                cancelButton.Click += new EventHandler(CancelButton_Click);

                //Add buttons to buttonContainer
                buttonContainer.AddChild(saveButton);
                buttonContainer.AddChild(new HorizontalSpacer());
                buttonContainer.AddChild(cancelButton);
            }

            //mainContainer.AddChild(new PrinterChooser());

            mainContainer.AddChild(headerRow);
            mainContainer.AddChild(ConnectionControlContainer);
            mainContainer.AddChild(buttonContainer);

            this.AddChild(mainContainer);

            BindSaveButtonHandlers();
            BindBaudRateHandlers();
        }
        public EditConnectionWidget(ConnectionWindow windowController, GuiWidget containerWindowToClose, Printer activePrinter = null, object state = null)
            : base(windowController, containerWindowToClose)
        {
            textImageButtonFactory.normalTextColor   = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.hoverTextColor    = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.pressedTextColor  = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.borderWidth       = 0;

            linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
            linkButtonFactory.fontSize  = 8;

            this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            this.AnchorAll();
            this.Padding = new BorderDouble(0);             //To be re-enabled once native borders are turned off

            GuiWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            mainContainer.AnchorAll();
            mainContainer.Padding         = new BorderDouble(3, 3, 3, 5);
            mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

            string headerTitle;

            if (activePrinter == null)
            {
                headerTitle                 = string.Format("Add a Printer");
                this.addNewPrinterFlag      = true;
                this.ActivePrinter          = new Printer();
                this.ActivePrinter.Name     = "Default Printer";
                this.ActivePrinter.BaudRate = "250000";
                try
                {
                    this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault();
                }
                catch (Exception e)
                {
                    Debug.Print(e.Message);
                    GuiWidget.BreakInDebugger();
                    //No active COM ports
                }
            }
            else
            {
                this.ActivePrinter = activePrinter;
                string editHeaderTitleTxt = LocalizedString.Get("Edit");
                headerTitle = string.Format("{1} - {0}", this.ActivePrinter.Name, editHeaderTitleTxt);
                if (this.ActivePrinter.BaudRate == null)
                {
                    this.ActivePrinter.BaudRate = "250000";
                }
                if (this.ActivePrinter.ComPort == null)
                {
                    try
                    {
                        this.ActivePrinter.ComPort = FrostedSerialPort.GetPortNames().FirstOrDefault();
                    }
                    catch (Exception e)
                    {
                        Debug.Print(e.Message);
                        GuiWidget.BreakInDebugger();
                        //No active COM ports
                    }
                }
            }

            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);

            headerRow.Margin  = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);
            headerRow.HAnchor = HAnchor.ParentLeftRight;
            {
                TextWidget headerLabel = new TextWidget(headerTitle, pointSize: 14);
                headerLabel.TextColor = this.defaultTextColor;

                headerRow.AddChild(headerLabel);
            }

            ConnectionControlContainer                 = new FlowLayoutWidget(FlowDirection.TopToBottom);
            ConnectionControlContainer.Padding         = new BorderDouble(5);
            ConnectionControlContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            ConnectionControlContainer.HAnchor         = HAnchor.ParentLeftRight;
            {
                TextWidget printerNameLabel = new TextWidget(LocalizedString.Get("Printer Name"), 0, 0, 10);
                printerNameLabel.TextColor = this.defaultTextColor;
                printerNameLabel.HAnchor   = HAnchor.ParentLeftRight;
                printerNameLabel.Margin    = new BorderDouble(0, 0, 0, 1);

                printerNameInput = new MHTextEditWidget(this.ActivePrinter.Name);

                printerNameInput.HAnchor |= HAnchor.ParentLeftRight;

                comPortLabelWidget = new FlowLayoutWidget();

                Button refreshComPorts = linkButtonFactory.Generate(LocalizedString.Get("(refresh)"));
                refreshComPorts.Margin  = new BorderDouble(left: 5);
                refreshComPorts.VAnchor = VAnchor.ParentBottom;
                refreshComPorts.Click  += new EventHandler(RefreshComPorts);

                FlowLayoutWidget comPortContainer = null;

#if !__ANDROID__
                TextWidget comPortLabel = new TextWidget(LocalizedString.Get("Serial Port"), 0, 0, 10);
                comPortLabel.TextColor = this.defaultTextColor;

                comPortLabelWidget.AddChild(comPortLabel);
                comPortLabelWidget.AddChild(refreshComPorts);
                comPortLabelWidget.Margin  = new BorderDouble(0, 0, 0, 10);
                comPortLabelWidget.HAnchor = HAnchor.ParentLeftRight;

                comPortContainer         = new FlowLayoutWidget(FlowDirection.TopToBottom);
                comPortContainer.Margin  = new BorderDouble(0);
                comPortContainer.HAnchor = HAnchor.ParentLeftRight;

                CreateSerialPortControls(comPortContainer, this.ActivePrinter.ComPort);
#endif

                TextWidget baudRateLabel = new TextWidget(LocalizedString.Get("Baud Rate"), 0, 0, 10);
                baudRateLabel.TextColor = this.defaultTextColor;
                baudRateLabel.Margin    = new BorderDouble(0, 0, 0, 10);
                baudRateLabel.HAnchor   = HAnchor.ParentLeftRight;

                baudRateWidget         = GetBaudRateWidget();
                baudRateWidget.HAnchor = HAnchor.ParentLeftRight;

                FlowLayoutWidget printerMakeContainer  = createPrinterMakeContainer();
                FlowLayoutWidget printerModelContainer = createPrinterModelContainer();

                enableAutoconnect           = new CheckBox(LocalizedString.Get("Auto Connect"));
                enableAutoconnect.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                enableAutoconnect.Margin    = new BorderDouble(top: 10);
                enableAutoconnect.HAnchor   = HAnchor.ParentLeft;
                if (this.ActivePrinter.AutoConnectFlag)
                {
                    enableAutoconnect.Checked = true;
                }

                if (state as StateBeforeRefresh != null)
                {
                    enableAutoconnect.Checked = ((StateBeforeRefresh)state).autoConnect;
                }

                SerialPortControl serialPortScroll = new SerialPortControl();

                if (comPortContainer != null)
                {
                    serialPortScroll.AddChild(comPortContainer);
                }

                ConnectionControlContainer.VAnchor = VAnchor.ParentBottomTop;
                ConnectionControlContainer.AddChild(printerNameLabel);
                ConnectionControlContainer.AddChild(printerNameInput);
                ConnectionControlContainer.AddChild(printerMakeContainer);
                ConnectionControlContainer.AddChild(printerModelContainer);
                ConnectionControlContainer.AddChild(comPortLabelWidget);
                ConnectionControlContainer.AddChild(serialPortScroll);
                ConnectionControlContainer.AddChild(baudRateLabel);
                ConnectionControlContainer.AddChild(baudRateWidget);
#if !__ANDROID__
                ConnectionControlContainer.AddChild(enableAutoconnect);
#endif
            }

            FlowLayoutWidget buttonContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
            buttonContainer.HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight;
            //buttonContainer.VAnchor = VAnchor.BottomTop;
            buttonContainer.Margin = new BorderDouble(0, 5, 0, 3);
            {
                //Construct buttons
                saveButton = textImageButtonFactory.Generate(LocalizedString.Get("Save"));
                //saveButton.VAnchor = VAnchor.Bottom;

                cancelButton = textImageButtonFactory.Generate(LocalizedString.Get("Cancel"));
                //cancelButton.VAnchor = VAnchor.Bottom;
                cancelButton.Click += new EventHandler(CancelButton_Click);

                //Add buttons to buttonContainer
                buttonContainer.AddChild(saveButton);
                buttonContainer.AddChild(new HorizontalSpacer());
                buttonContainer.AddChild(cancelButton);
            }

            //mainContainer.AddChild(new PrinterChooser());

            mainContainer.AddChild(headerRow);
            mainContainer.AddChild(ConnectionControlContainer);
            mainContainer.AddChild(buttonContainer);

#if __ANDROID__
            this.AddChild(new SoftKeyboardContentOffset(mainContainer, SoftKeyboardContentOffset.AndroidKeyboardOffset));
#else
            this.AddChild(mainContainer);
#endif

            BindSaveButtonHandlers();
            BindBaudRateHandlers();
        }