private GuiWidget CreatePrintLevelingControlsContainer()
        {
            Button   editButton;
            GroupBox printLevelingControlsContainer = new GroupBox(textImageButtonFactory.GenerateGroupBoxLabelWithEdit(LocalizedString.Get("Automatic Calibration"), out editButton));

            editButton.Click += (sender, e) =>
            {
                if (editLevelingSettingsWindow == null)
                {
                    editLevelingSettingsWindow         = new EditLevelingSettingsWindow();
                    editLevelingSettingsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { editLevelingSettingsWindow = null; };
                }
                else
                {
                    editLevelingSettingsWindow.BringToFront();
                }
            };

            printLevelingControlsContainer.Margin      = new BorderDouble(0);
            printLevelingControlsContainer.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
            printLevelingControlsContainer.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            printLevelingControlsContainer.HAnchor     = Agg.UI.HAnchor.ParentLeftRight;
            printLevelingControlsContainer.Height      = 68;

            {
                FlowLayoutWidget buttonBar = new FlowLayoutWidget();
                buttonBar.HAnchor |= HAnchor.ParentLeftRight;
                buttonBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
                buttonBar.Margin   = new BorderDouble(0, 0, 0, 0);
                buttonBar.Padding  = new BorderDouble(0);

                this.textImageButtonFactory.FixedHeight = TallButtonHeight;

                Button runPrintLevelingButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
                runPrintLevelingButton.Margin  = new BorderDouble(left: 6);
                runPrintLevelingButton.VAnchor = VAnchor.ParentCenter;
                runPrintLevelingButton.Click  += new ButtonBase.ButtonEventHandler(runPrintLeveling_Click);

                Agg.Image.ImageBuffer levelingImage = new Agg.Image.ImageBuffer();
                ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "leveling-24x24.png"), levelingImage);
                if (!ActiveTheme.Instance.IsDarkTheme)
                {
                    InvertLightness.DoInvertLightness(levelingImage);
                }

                ImageWidget levelingIcon = new ImageWidget(levelingImage);
                levelingIcon.Margin = new BorderDouble(right: 6);

                enablePrintLevelingButton         = textImageButtonFactory.Generate("Enable".Localize().ToUpper());
                enablePrintLevelingButton.Margin  = new BorderDouble(left: 6);
                enablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
                enablePrintLevelingButton.Click  += new ButtonBase.ButtonEventHandler(enablePrintLeveling_Click);

                disablePrintLevelingButton         = textImageButtonFactory.Generate("Disable".Localize().ToUpper());
                disablePrintLevelingButton.Margin  = new BorderDouble(left: 6);
                disablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
                disablePrintLevelingButton.Click  += new ButtonBase.ButtonEventHandler(disablePrintLeveling_Click);

                CheckBox doLevelingCheckBox = new CheckBox(LocalizedString.Get("Enable Automatic Print Leveling"));
                doLevelingCheckBox.Margin    = new BorderDouble(left: 3);
                doLevelingCheckBox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                doLevelingCheckBox.VAnchor   = VAnchor.ParentCenter;
                doLevelingCheckBox.Checked   = ActivePrinterProfile.Instance.DoPrintLeveling;

                printLevelingStatusLabel = new TextWidget("");
                printLevelingStatusLabel.AutoExpandBoundsToText = true;
                printLevelingStatusLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                printLevelingStatusLabel.VAnchor   = VAnchor.ParentCenter;

                GuiWidget hSpacer = new GuiWidget();
                hSpacer.HAnchor = HAnchor.ParentLeftRight;

                buttonBar.AddChild(levelingIcon);
                //buttonBar.AddChild(doLevelingCheckBox);
                buttonBar.AddChild(printLevelingStatusLabel);
                buttonBar.AddChild(hSpacer);
                buttonBar.AddChild(enablePrintLevelingButton);
                buttonBar.AddChild(disablePrintLevelingButton);
                buttonBar.AddChild(runPrintLevelingButton);
                doLevelingCheckBox.CheckedStateChanged += (sender, e) =>
                {
                    ActivePrinterProfile.Instance.DoPrintLeveling = doLevelingCheckBox.Checked;
                };
                ActivePrinterProfile.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) =>
                {
                    SetPrintLevelButtonVisiblity();
                }, ref unregisterEvents);

                printLevelingControlsContainer.AddChild(buttonBar);
            }
            SetPrintLevelButtonVisiblity();
            return(printLevelingControlsContainer);
        }
        private GuiWidget CreatePrintLevelingControlsContainer()
        {
            Button editButton;
            GroupBox printLevelingControlsContainer = new GroupBox(textImageButtonFactory.GenerateGroupBoxLabelWithEdit(LocalizedString.Get("Automatic Calibration"), out editButton));
            editButton.Click += (sender, e) =>
            {
                UiThread.RunOnIdle((state) =>
                {
                    if (editLevelingSettingsWindow == null)
                    {
                        editLevelingSettingsWindow = new EditLevelingSettingsWindow();
                        editLevelingSettingsWindow.Closed += (sender2, e2) =>
                        {
                            editLevelingSettingsWindow = null;
                        };
                    }
                    else
                    {
                        editLevelingSettingsWindow.BringToFront();
                    }
                });
            };

            printLevelingControlsContainer.Margin = new BorderDouble(0);
            printLevelingControlsContainer.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            printLevelingControlsContainer.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            printLevelingControlsContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
            printLevelingControlsContainer.Height = 68;

            {
                FlowLayoutWidget buttonBar = new FlowLayoutWidget();
                buttonBar.HAnchor |= HAnchor.ParentLeftRight;
                buttonBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
                buttonBar.Margin = new BorderDouble(0, 0, 0, 0);
                buttonBar.Padding = new BorderDouble(0);

                this.textImageButtonFactory.FixedHeight = TallButtonHeight;

                Button runPrintLevelingButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
                runPrintLevelingButton.Margin = new BorderDouble(left:6);
                runPrintLevelingButton.VAnchor = VAnchor.ParentCenter;
                runPrintLevelingButton.Click += (sender, e) =>
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration);
                    });
                };

                Agg.Image.ImageBuffer levelingImage = new Agg.Image.ImageBuffer();
				ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath,"Icons", "PrintStatusControls", "leveling-24x24.png"), levelingImage);
                if (!ActiveTheme.Instance.IsDarkTheme)
                {
                    InvertLightness.DoInvertLightness(levelingImage);
                }
                
                ImageWidget levelingIcon = new ImageWidget(levelingImage);
				levelingIcon.Margin = new BorderDouble (right: 6);

                enablePrintLevelingButton = textImageButtonFactory.Generate("Enable".Localize().ToUpper());
				enablePrintLevelingButton.Margin = new BorderDouble(left:6);
				enablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
				enablePrintLevelingButton.Click += new ButtonBase.ButtonEventHandler(enablePrintLeveling_Click);

                disablePrintLevelingButton = textImageButtonFactory.Generate("Disable".Localize().ToUpper());
				disablePrintLevelingButton.Margin = new BorderDouble(left:6);
				disablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
				disablePrintLevelingButton.Click += new ButtonBase.ButtonEventHandler(disablePrintLeveling_Click);

				printLevelingStatusLabel = new TextWidget ("");
				printLevelingStatusLabel.AutoExpandBoundsToText = true;
				printLevelingStatusLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
				printLevelingStatusLabel.VAnchor = VAnchor.ParentCenter;

				GuiWidget hSpacer = new GuiWidget ();
				hSpacer.HAnchor = HAnchor.ParentLeftRight;

                buttonBar.AddChild(levelingIcon);
				buttonBar.AddChild (printLevelingStatusLabel);
				buttonBar.AddChild (hSpacer);
				buttonBar.AddChild(enablePrintLevelingButton);
				buttonBar.AddChild(disablePrintLevelingButton);
                buttonBar.AddChild(runPrintLevelingButton);
                ActivePrinterProfile.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) =>
                {
					SetPrintLevelButtonVisiblity();

                }, ref unregisterEvents);

                printLevelingControlsContainer.AddChild(buttonBar);
            }
			SetPrintLevelButtonVisiblity ();
            return printLevelingControlsContainer;
        }