public virtual void Invalidate( TextPosition selectionStart, TextPosition selectionEnd, bool repaint) { this.selectionPolygons = (RectangleF[])null; TextBoxViewElement viewElement = this.textBoxElement.ViewElement; if (object.Equals((object)selectionStart, (object)selectionEnd) || selectionEnd == (TextPosition)null) { viewElement.Invalidate(); } else { TextPosition.Swap(ref selectionStart, ref selectionEnd); LineInfo line1 = selectionStart.Line; LineInfo line2 = selectionEnd.Line; ReadOnlyCollection <LineInfo> lines = (ReadOnlyCollection <LineInfo>)viewElement.Lines; int index = lines.IndexOf(line1); int lineSpacing = viewElement.LineSpacing; List <RectangleF> rectangleFList = new List <RectangleF>(); for (; index < lines.Count; ++index) { LineInfo currentLine = lines[index]; RectangleF rectangle = this.GetRectangle(currentLine); if (currentLine == line1) { PointF location = viewElement.GetLocation(selectionStart); rectangle.Width += rectangle.X - location.X; rectangle.X = location.X; } if (currentLine == line2) { PointF location = viewElement.GetLocation(selectionEnd); rectangle.Width = location.X - rectangle.X; } if (currentLine != line1) { rectangle.Y -= (float)lineSpacing; rectangle.Height += (float)lineSpacing; } rectangleFList.Add(rectangle); if (currentLine == line2) { break; } } this.selectionPolygons = rectangleFList.ToArray(); if (!repaint) { return; } viewElement.Invalidate(); } }
protected virtual TextPosition NavigateToLine( KeyEventArgs keys, TextPosition position) { Keys keyCode = keys.KeyCode; TextBoxViewElement viewElement = this.textBoxElement.ViewElement; ReadOnlyCollection <LineInfo> lines = (ReadOnlyCollection <LineInfo>)viewElement.Lines; LineInfo line = position.Line; int num = lines.IndexOf(line); if (keyCode == Keys.Up && num > 0) { line = lines[num - 1]; } else if (keyCode == Keys.Down && num < lines.Count - 1) { line = lines[num + 1]; } if (position.Line == line) { return(position); } float x = viewElement.GetLocation(position).X + viewElement.ScrollOffset.Width; return(this.GetTextPositionFromLine(line, x)); }
public virtual void SetCaretPosition() { if (this.selectionStart == (TextPosition)null) { return; } TextBoxControlCaret caret = this.textBoxElement.Caret; TextPosition caretPosition = this.CaretPosition; TextBoxViewElement viewElement = this.textBoxElement.ViewElement; PointF location = viewElement.GetLocation(caretPosition); SizeF scrollOffset = viewElement.ScrollOffset; location.X += scrollOffset.Width; location.Y += scrollOffset.Height; caret.Height = (int)caretPosition.Line.Size.Height; Point point = this.textBoxElement.PointFromControl(Point.Truncate(location)); caret.Position = point; }