public static DialogResult Show(IWin32Window owner, Control control, string caption, bool canResize) { int btnHeight; using (var btn = CreateButton("test", DialogResult.None)) { btnHeight = btn.Height; } var box = new frmControlBox { Text = caption, FormBorderStyle = canResize ? FormBorderStyle.Sizable : FormBorderStyle.FixedDialog }; if (canResize) { box.MaximizeBox = true; } if (!control.MinimumSize.IsEmpty) { box.MinimumSize = new Size(control.MinimumSize.Width + 2 * Margin, control.MinimumSize.Height + btnHeight + 3 * Margin) + (box.Size - box.ClientSize); } if (!control.MaximumSize.IsEmpty) { box.MaximumSize = new Size(control.MaximumSize.Width + 2 * Margin, control.MaximumSize.Height + btnHeight + 3 * Margin) + (box.Size - box.ClientSize); } box.ClientSize = new Size(control.Width + 2 * Margin, control.Height + btnHeight + 3 * Margin); control.Location = new Point(Margin, Margin); control.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; control.Parent = box; var buttons = GetControlButtons(control); AddButtons(box, buttons.ToArray(), -1); foreach (var button in buttons) { if (button.DialogResult == DialogResult.OK) { box.AcceptButton = button; } else if (button.DialogResult == DialogResult.Cancel) { box.CancelButton = button; } } return(owner != null?box.ShowDialog(owner) : box.ShowDialog()); }
public static DialogResult Show(IWin32Window owner, Control control, string caption, MessageBoxButtons buttons, int defaultButton, bool canResize, bool needButtons) { int btnHeight; using (var btn = CreateButton("test", DialogResult.None)) { btnHeight = btn.Height; } var box = new frmControlBox { Text = caption, FormBorderStyle = canResize ? FormBorderStyle.Sizable : FormBorderStyle.FixedDialog }; if (canResize) { box.MaximizeBox = true; } if (!control.MinimumSize.IsEmpty) { box.MinimumSize = new Size(control.MinimumSize.Width + 2 * Margin, control.MinimumSize.Height + btnHeight + 3 * Margin) + (box.Size - box.ClientSize); } if (!control.MaximumSize.IsEmpty) { box.MaximumSize = new Size(control.MaximumSize.Width + 2 * Margin, control.MaximumSize.Height + btnHeight + 3 * Margin) + (box.Size - box.ClientSize); } box.ClientSize = new Size(control.Width + 2 * Margin, control.Height + btnHeight + 3 * Margin); control.Location = new Point(Margin, Margin); control.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; AppendButtons(box, control, buttons, defaultButton, needButtons); control.Parent = box; return(owner != null?box.ShowDialog(owner) : box.ShowDialog()); }
public static void ShowFloatWindow(IWin32Window owner, Control control, string caption, bool canResize, bool allowMaximize = false) { #region Dialog creation int btnHeight; using (var btn = CreateButton("test", DialogResult.None)) { btnHeight = btn.Height; } var box = new frmControlBox { Owner = owner as Form, ShowInTaskbar = true, Text = caption }; //box.StartPosition = FormStartPosition.CenterParent; if (canResize && allowMaximize) { box.FormBorderStyle = FormBorderStyle.Sizable; box.MaximizeBox = true; box.MinimizeBox = false; } else if (canResize) { box.FormBorderStyle = FormBorderStyle.SizableToolWindow; } else { box.FormBorderStyle = FormBorderStyle.FixedDialog; } //box.FormBorderStyle = canResize ? FormBorderStyle.Sizable: FormBorderStyle.FixedDialog; if (!control.MinimumSize.IsEmpty) { box.MinimumSize = new Size(control.MinimumSize.Width + 2 * Margin, control.MinimumSize.Height + btnHeight + 3 * Margin) + (box.Size - box.ClientSize); } if (!control.MaximumSize.IsEmpty) { box.MaximumSize = new Size(control.MaximumSize.Width + 2 * Margin, control.MaximumSize.Height + btnHeight + 3 * Margin) + (box.Size - box.ClientSize); } box.ClientSize = new Size(control.Width + 2 * Margin, control.Height + btnHeight + 3 * Margin); control.Location = new Point(Margin, Margin); control.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; control.Parent = box; var controlButtons = GetControlButtons(control); if (controlButtons.Count == 0) { controlButtons.Add(CreateButton("Close", DialogResult.Cancel)); box.CancelButton = controlButtons[0]; controlButtons[0].Click += box_Disposed; } else { foreach (var btn in controlButtons) { if (btn.DialogResult == DialogResult.Cancel) { btn.Click += box_Disposed; box.CancelButton = btn; break; } } } AddButtons(box, controlButtons.ToArray(), 0); #endregion box.Disposed += box_Disposed; if (owner != null) { box.Show(owner); } else { box.Show(); } }