public static void ApplyPreferredSize(Control control) { if (AutoSizePanel.CanAutoSizeWidth(control) || AutoSizePanel.CanAutoSizeHeight(control)) { Size fitToContentsSize = AutoSizePanel.GetFitToContentsSize(control); if (control.Size != fitToContentsSize) { control.Size = AutoSizePanel.GetAutoSizeModeSize(control, fitToContentsSize); } } }
protected override void OnLayout(LayoutEventArgs levent) { if (this.AutoSize) { AutoSizePanel.ApplyPreferredSize(this); } base.OnLayout(levent); if (this.AutoSize) { AutoSizePanel.ApplyPreferredSize(this); } if (this.AutoScroll) { base.AdjustFormScrollbars(this.AutoScroll); } }
public ExceptionDialog() { ExchangeButton exchangeButton = new ExchangeButton(); ExchangeButton exchangeButton2 = new ExchangeButton(); this.additionalMessages = new ExchangeTextBox(); AutoSizePanel autoSizePanel = new AutoSizePanel(); Label label = new Label(); TableLayoutPanel tableLayoutPanel = new TableLayoutPanel(); base.SuspendLayout(); base.ContentPanel.SuspendLayout(); tableLayoutPanel.SuspendLayout(); base.ButtonsPanel.SuspendLayout(); tableLayoutPanel.AutoSize = true; tableLayoutPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; tableLayoutPanel.ColumnCount = 1; tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100f)); tableLayoutPanel.Controls.Add(label, 0, 0); tableLayoutPanel.Controls.Add(autoSizePanel, 0, 1); tableLayoutPanel.Dock = DockStyle.Fill; tableLayoutPanel.RowCount = 2; tableLayoutPanel.RowStyles.Add(new RowStyle()); tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100f)); tableLayoutPanel.TabIndex = 0; exchangeButton.AutoSize = true; exchangeButton.Click += this.reportButton_Click; exchangeButton.Dock = DockStyle.Left; exchangeButton.FocusedAlwaysOnClick = false; exchangeButton.Margin = new Padding(0); exchangeButton.Name = "reportButton"; exchangeButton.TabIndex = 1; exchangeButton.Text = Strings.SendWatsonReport; exchangeButton2.AutoSize = true; exchangeButton2.Click += this.helpButton_Click; exchangeButton2.Dock = DockStyle.Right; exchangeButton2.FocusedAlwaysOnClick = false; exchangeButton2.Margin = new Padding(8, 0, 0, 0); exchangeButton2.Name = "helpButton"; exchangeButton2.TabIndex = 2; exchangeButton2.Text = "&Help"; base.ButtonsPanel.Controls.Add(exchangeButton2); base.ButtonsPanel.ColumnCount = 4; base.ButtonsPanel.ColumnStyles.Insert(1, new ColumnStyle()); base.ButtonsPanel.ColumnStyles.Add(new ColumnStyle()); base.ButtonsPanel.Controls.Add(exchangeButton, 0, 0); base.ButtonsPanel.Controls.Add(exchangeButton2, 3, 0); this.additionalMessages.Location = new Point(0, 0); this.additionalMessages.Margin = new Padding(0); this.additionalMessages.Size = new Size(406, 147); this.additionalMessages.Name = "additionalMessages"; this.additionalMessages.ReadOnly = true; this.additionalMessages.Multiline = true; this.additionalMessages.ScrollBars = ScrollBars.Vertical; this.additionalMessages.TabIndex = 0; this.additionalMessages.TabStop = false; this.additionalMessages.Dock = DockStyle.Fill; autoSizePanel.BackColor = SystemColors.Window; autoSizePanel.Controls.Add(this.additionalMessages); autoSizePanel.Dock = DockStyle.Fill; autoSizePanel.Margin = new Padding(3, 0, 0, 0); autoSizePanel.Name = "additionalMessagesPanel"; autoSizePanel.Size = new Size(406, 147); autoSizePanel.TabIndex = 1; autoSizePanel.TabStop = false; label.AutoSize = true; label.Dock = DockStyle.Top; label.Font = new Font(this.Font, FontStyle.Bold); label.Location = new Point(0, 25); label.Name = "infoCaption"; label.Size = new Size(130, 13); label.TabIndex = 0; label.Text = Strings.AdditionalInformation; base.ContentPanel.Controls.Add(tableLayoutPanel); base.ContentPanel.Controls.SetChildIndex(tableLayoutPanel, 0); base.Name = "ExceptionDialog"; this.Text = Strings.ExceptionDialogTitle(UIService.DefaultCaption); base.ButtonsPanel.ResumeLayout(false); base.ButtonsPanel.PerformLayout(); tableLayoutPanel.ResumeLayout(false); tableLayoutPanel.PerformLayout(); base.ContentPanel.ResumeLayout(false); base.ContentPanel.PerformLayout(); base.ResumeLayout(false); base.PerformLayout(); exchangeButton2.Visible = false; }
public static Size GetFitToContentsSize(Control control) { if (control.HasChildren) { int num = int.MinValue; int num2 = int.MinValue; int num3 = 0; int num4 = 0; bool flag = false; bool flag2 = true; bool flag3 = true; for (int i = 0; i < control.Controls.Count; i++) { Control control2 = control.Controls[i]; if (control2.Visible) { flag = true; switch (control2.Dock) { case DockStyle.None: { flag2 = false; flag3 = false; Size size = control2.Size; num = Math.Max(num, control2.Left + size.Width); num2 = Math.Max(num2, control2.Top + size.Height); break; } case DockStyle.Top: case DockStyle.Bottom: flag3 = false; num4 += control2.Height; break; case DockStyle.Left: case DockStyle.Right: flag2 = false; num3 += control2.Width; break; case DockStyle.Fill: num3 += control2.Width; num4 += control2.Height; break; } } } ScrollableControl scrollableControl = control as ScrollableControl; if (scrollableControl != null) { ScrollableControl.DockPaddingEdges dockPadding = scrollableControl.DockPadding; num += dockPadding.Right; num2 += dockPadding.Bottom; num3 += dockPadding.Left + dockPadding.Right; num4 += dockPadding.Top + dockPadding.Bottom; } num = Math.Max(num, num3); num2 = Math.Max(num2, num4); if (!flag || !AutoSizePanel.CanAutoSizeWidth(control) || flag2) { num = control.Size.Width; } if (!flag || !AutoSizePanel.CanAutoSizeHeight(control) || flag3) { num2 = control.Size.Height; } return(AutoSizePanel.GetAutoSizeModeSize(control, new Size(num, num2))); } return(control.Size); }