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()); }