namespace Sunfish.WinForms;
/// <summary>
/// Ventanas no modales (Show) centradas sobre su ventana padre: CenterParent solo funciona con
/// ShowDialog, asi que se colocan a mano y sin salirse del area de trabajo de esa pantalla.
/// </summary>
internal static class UiPlacement
{
public static void ShowCentered(Form form, Form owner)
{
form.StartPosition = FormStartPosition.Manual;
form.Owner = owner;
var area = Screen.FromControl(owner).WorkingArea;
var size = form.Size;
int x = owner.Left + (owner.Width - size.Width) / 2;
int y = owner.Top + (owner.Height - size.Height) / 2;
x = Math.Max(area.Left, Math.Min(x, area.Right - size.Width));
y = Math.Max(area.Top, Math.Min(y, area.Bottom - size.Height));
form.Location = new Point(x, y);
form.Show(owner);
}
}