private void QuickEditTextWin_Shown(object sender, EventArgs e) { { I4Rect win = new I4Rect() { L = this.ParentWin.Left, T = this.ParentWin.Top, W = Math.Max(300, this.ParentWin.Width + 50), H = Math.Max(300, this.ParentWin.Height + 50), }; foreach (I4Rect screen in Tools.GetAllScreen().Where(screen => Tools.IsCrashed(screen, win))) { win = Tools.IntoScreen(screen, win); break; } this.Left = win.L; this.Top = win.T; this.Width = win.W; this.Height = win.H; } Tools.PostShown(this); }
public static I4Rect IntoScreen(I4Rect screen, I4Rect win) { if (screen.R < win.R) { win.L = screen.R - win.W; } if (win.L < screen.L) { win.L = screen.L; } if (screen.B < win.B) { win.T = screen.B - win.H; } if (win.T < screen.T) { win.T = screen.T; } return(win); }
public static bool IsCrashed(I4Rect a, I4Rect b) { return (a.L < b.R && b.L < a.R && a.T < b.B && b.T < a.B); }