protected override void OnLayout(LayoutEventArgs levent) { // Bottom-right Buttons int buttonsBottomMargin = UI.ScaleHeight(8); int buttonsRightMargin = UI.ScaleWidth(8); int buttonsHMargin = UI.ScaleWidth(8); this.baseCancelButton.Location = new Point( ClientSize.Width - this.baseOkButton.Width - buttonsRightMargin, ClientSize.Height - buttonsBottomMargin - this.baseCancelButton.Height); this.baseOkButton.Location = new Point( this.baseCancelButton.Left - buttonsHMargin - this.baseOkButton.Width, ClientSize.Height - buttonsBottomMargin - this.baseOkButton.Height); int previewBottomMargin = UI.ScaleHeight(8); // Set up layout properties int topMargin = UI.ScaleHeight(6); int leftMargin = UI.ScaleWidth(8); int leftColumWidth = UI.ScaleWidth(200); int columHMargin = UI.ScaleWidth(8); int rightMargin = UI.ScaleWidth(8); int vMargin = UI.ScaleHeight(4); int rightColumnX = leftMargin + leftColumWidth + columHMargin; int rightColumnWidth = ClientSize.Width - rightColumnX - rightMargin; int defaultsButtonTopMargin = UI.ScaleHeight(12); int headerXAdjustment = -3; // Left column this.settingsHeader.Location = new Point(leftMargin + headerXAdjustment, topMargin); this.settingsHeader.Width = leftColumWidth - headerXAdjustment; this.settingsHeader.PerformLayout(); this.saveConfigPanel.Location = new Point(leftMargin, this.settingsHeader.Bottom + vMargin); this.saveConfigPanel.Width = leftColumWidth; this.saveConfigPanel.PerformLayout(); //this.saveConfigWidget.Location = new Point(0, 0); this.saveConfigWidget.Width = this.saveConfigPanel.Width - SystemInformation.VerticalScrollBarWidth; // Right column this.previewHeader.Location = new Point(rightColumnX + headerXAdjustment, topMargin); this.previewHeader.Width = rightColumnWidth - headerXAdjustment; this.previewHeader.PerformLayout(); this.documentView.Location = new Point(rightColumnX, this.previewHeader.Bottom + vMargin); this.documentView.Size = new Size( rightColumnWidth, this.baseCancelButton.Top - previewBottomMargin - this.documentView.Top); // Finish up setting the height on the left side this.saveConfigPanel.Height = this.documentView.Bottom - this.saveConfigPanel.Top - this.defaultsButton.Height - defaultsButtonTopMargin; this.saveConfigWidget.PerformLayout(); int saveConfigHeight = Math.Min(this.saveConfigPanel.Height, this.saveConfigWidget.Height); this.defaultsButton.PerformLayout(); this.defaultsButton.Location = new Point( leftMargin + (leftColumWidth - this.defaultsButton.Width) / 2, this.saveConfigPanel.Top + saveConfigHeight + defaultsButtonTopMargin); MinimumSize = UI.ScaleSize(unscaledMinSize); base.OnLayout(levent); }
protected override void OnLayout(LayoutEventArgs levent) { int leftMargin = UI.ScaleWidth(8); int rightMargin = UI.ScaleWidth(8); int topMargin = UI.ScaleHeight(8); int bottomMargin = UI.ScaleHeight(8); int imageToIntroHMargin = UI.ScaleWidth(8); int topSectionToLinksVMargin = UI.ScaleHeight(8); int commandButtonVMargin = UI.ScaleHeight(0); int afterCommandButtonsVMargin = UI.ScaleHeight(8); int insetWidth = ClientSize.Width - leftMargin - rightMargin; if (this.taskImagePB.Image == null) { this.taskImagePB.Location = new Point(0, topMargin); this.taskImagePB.Size = new Size(0, 0); this.taskImagePB.Visible = false; } else { this.taskImagePB.Location = new Point(leftMargin, topMargin); if (this.scaleTaskImageWithDpi) { this.taskImagePB.Size = UI.ScaleSize(this.taskImagePB.Image.Size); } else { this.taskImagePB.Size = this.taskImagePB.Image.Size; } this.taskImagePB.Visible = true; } this.introTextLabel.Location = new Point(this.taskImagePB.Right + imageToIntroHMargin, this.taskImagePB.Top); this.introTextLabel.Width = ClientSize.Width - this.introTextLabel.Left - rightMargin; this.introTextLabel.Height = this.introTextLabel.GetPreferredSize(new Size(this.introTextLabel.Width, 1)).Height; int y = Math.Max(this.taskImagePB.Bottom, this.introTextLabel.Bottom); y += topSectionToLinksVMargin; if (!string.IsNullOrEmpty(this.auxButton.Text)) { this.auxButton.Visible = true; this.auxButton.Location = new Point(leftMargin, y); this.auxButton.PerformLayout(); y += this.auxButton.Height; y += topSectionToLinksVMargin; } else { this.auxButton.Visible = false; } if (this.commandButtons != null) { this.separator.Location = new Point(leftMargin, y); this.separator.Width = insetWidth; y += this.separator.Height; for (int i = 0; i < this.commandButtons.Length; ++i) { this.commandButtons[i].Location = new Point(leftMargin, y); this.commandButtons[i].Width = insetWidth; this.commandButtons[i].PerformLayout(); y += this.commandButtons[i].Height + commandButtonVMargin; } y += afterCommandButtonsVMargin; } this.ClientSize = new Size(ClientSize.Width, y); base.OnLayout(levent); }
private void LoadPositions() { Size minSize = UI.ScaleSize(unscaledMinSize); Form owner = Owner; Rectangle ownerWindowBounds; if (owner != null) { ownerWindowBounds = owner.Bounds; } else { ownerWindowBounds = Screen.PrimaryScreen.WorkingArea; } // Determine what our default relative bounds should be // These are client bounds that are relative to our owner's window bounds. // Or if we have no window, then this is for the primary monitor. Rectangle defaultRelativeClientBounds = new Rectangle( (ownerWindowBounds.Width - minSize.Width) / 2, (ownerWindowBounds.Height - minSize.Height) / 2, minSize.Width, minSize.Height); // Load the relative client bounds for the dialog. This is a client bounds that is // relative to the owner's window bounds. Rectangle relativeClientBounds; FormWindowState newFws; try { string newFwsString = Settings.CurrentUser.GetString(SettingNames.WindowState, FormWindowState.Normal.ToString()); newFws = (FormWindowState)Enum.Parse(typeof(FormWindowState), newFwsString); int newLeft = Settings.CurrentUser.GetInt32(SettingNames.Left, defaultRelativeClientBounds.Left); int newTop = Settings.CurrentUser.GetInt32(SettingNames.Top, defaultRelativeClientBounds.Top); int newWidth = Math.Max(minSize.Width, Settings.CurrentUser.GetInt32(SettingNames.Width, defaultRelativeClientBounds.Width)); int newHeight = Math.Max(minSize.Height, Settings.CurrentUser.GetInt32(SettingNames.Height, defaultRelativeClientBounds.Height)); relativeClientBounds = new Rectangle(newLeft, newTop, newWidth, newHeight); } catch (Exception) { relativeClientBounds = defaultRelativeClientBounds; newFws = FormWindowState.Normal; } // Convert to client bounds from from client bounds that are relative to the owner's window bounds. // This will be our proposed client bounds. Rectangle proposedClientBounds = new Rectangle( relativeClientBounds.Left + ownerWindowBounds.Left, relativeClientBounds.Top + owner.Top, relativeClientBounds.Width, relativeClientBounds.Height); // Keep the default client bounds around as well Rectangle defaultClientBounds = new Rectangle( defaultRelativeClientBounds.Left + ownerWindowBounds.Left, defaultRelativeClientBounds.Top + ownerWindowBounds.Top, defaultRelativeClientBounds.Width, defaultRelativeClientBounds.Height); // Start applying the values. SuspendLayout(); try { Rectangle newClientBounds = ValidateAndAdjustNewBounds(owner, proposedClientBounds, defaultClientBounds); Rectangle newWindowBounds = ClientBoundsToWindowBounds(newClientBounds); Bounds = newWindowBounds; WindowState = newFws; } finally { ResumeLayout(true); } }