public virtual void MoveFormAwayFromSelection() { if (!Visible) { return; } if (!AutoPosition) { return; } int pos = Scintilla.Caret.Position; int x = Scintilla.PointXFromPosition(pos); int y = Scintilla.PointYFromPosition(pos); Point cursorPoint = Scintilla.PointToScreen(new Point(x, y)); Rectangle r = new Rectangle(Location, Size); if (r.Contains(cursorPoint)) { Point newLocation; if (cursorPoint.Y < (Screen.PrimaryScreen.Bounds.Height / 2)) { // Top half of the screen newLocation = Scintilla.PointToClient( new Point(Location.X, cursorPoint.Y + Scintilla.Lines.Current.Height * 2) ); } else { // Bottom half of the screen newLocation = Scintilla.PointToClient( new Point(Location.X, cursorPoint.Y - Height - (Scintilla.Lines.Current.Height * 2)) ); } newLocation = Scintilla.PointToScreen(newLocation); Location = newLocation; } }