// This was taken from FindReplaceDialog. Obviously some refactoring is called for
// since we have common code. However I'm holding off on this because I'm coming
// up with some other ideas for the FindReplaceDialog. Right now every scintilla
// gets its own FindReplaceDialog, but they really need to be sharable across
// multiple scintillas much like how DropMarkers work.
private void MoveFormAwayFromSelection()
{
if (!Visible)
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;
}
}