ARCed.Scintilla.GoToDialog.MoveFormAwayFromSelection C# (CSharp) Method

MoveFormAwayFromSelection() private method

private MoveFormAwayFromSelection ( ) : void
return void
        private void MoveFormAwayFromSelection()
        {
            if (!Visible)
                return;

            int pos = this.Scintilla.Caret.Position;
            int x = this.Scintilla.PointXFromPosition(pos);
            int y = this.Scintilla.PointYFromPosition(pos);

            Point cursorPoint = this.Scintilla.PointToScreen(new Point(x, y));

            var 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 = this.Scintilla.PointToClient(
                        new Point(Location.X, cursorPoint.Y + this.Scintilla.Lines.Current.Height * 2)
                        );
                }
                else
                {
                    // FixedY half of the screen
                    newLocation = this.Scintilla.PointToClient(
                        new Point(Location.X, cursorPoint.Y - Height - (this.Scintilla.Lines.Current.Height * 2))
                        );
                }
                newLocation = this.Scintilla.PointToScreen(newLocation);
                Location = newLocation;
            }
        }