diff --git a/FastColoredTextBox/AutocompleteItem.cs b/FastColoredTextBox/AutocompleteItem.cs index 59feec4d..1b2ee9e0 100644 --- a/FastColoredTextBox/AutocompleteItem.cs +++ b/FastColoredTextBox/AutocompleteItem.cs @@ -181,11 +181,11 @@ public override void OnSelected(AutocompleteMenu popupMenu, SelectedEventArgs e) { for (int iLine = p1.iLine + 1; iLine <= p2.iLine; iLine++) { - e.Tb.Selection.Start = new Place(0, iLine); + e.Tb.Selection.SetStartAndEnd(new Place(0, iLine)); e.Tb.DoAutoIndent(iLine); } } - e.Tb.Selection.Start = p1; + e.Tb.Selection.SetStartAndEnd(p1); //move caret position right and find char ^ while (e.Tb.Selection.CharBeforeStart != '^') if (!e.Tb.Selection.GoRightThroughFolded()) diff --git a/FastColoredTextBox/Bookmarks.cs b/FastColoredTextBox/Bookmarks.cs index ad220d98..98b8ef04 100644 --- a/FastColoredTextBox/Bookmarks.cs +++ b/FastColoredTextBox/Bookmarks.cs @@ -231,7 +231,7 @@ public class Bookmark /// public virtual void DoVisible() { - TB.Selection.Start = new Place(0, LineIndex); + TB.Selection.SetStartAndEnd(new Place(0, LineIndex)); TB.DoRangeVisible(TB.Selection, true); TB.Invalidate(); } diff --git a/FastColoredTextBox/Commands.cs b/FastColoredTextBox/Commands.cs index c83ac962..885354a5 100644 --- a/FastColoredTextBox/Commands.cs +++ b/FastColoredTextBox/Commands.cs @@ -33,7 +33,7 @@ public override void Undo() case '\n': MergeLines(sel.Start.iLine, ts); break; case '\r': break; case '\b': - ts.CurrentTB.Selection.Start = lastSel.Start; + ts.CurrentTB.Selection.SetStartAndEnd(lastSel.Start); char cc = '\x0'; if (deletedChar != '\x0') { @@ -45,12 +45,12 @@ public override void Undo() ts.CurrentTB.ExpandBlock(sel.Start.iLine); for (int i = sel.FromX; i < lastSel.FromX; i++) ts[sel.Start.iLine].RemoveAt(sel.Start.iChar); - ts.CurrentTB.Selection.Start = sel.Start; + ts.CurrentTB.Selection.SetStartAndEnd(sel.Start); break; default: ts.CurrentTB.ExpandBlock(sel.Start.iLine); ts[sel.Start.iLine].RemoveAt(sel.Start.iChar); - ts.CurrentTB.Selection.Start = sel.Start; + ts.CurrentTB.Selection.SetStartAndEnd(sel.Start); break; } @@ -112,7 +112,7 @@ internal static void InsertChar(char c, ref char deletedChar, TextSource ts) { deletedChar = ts[tb.Selection.Start.iLine][tb.Selection.Start.iChar - 1].c; ts[tb.Selection.Start.iLine].RemoveAt(tb.Selection.Start.iChar - 1); - tb.Selection.Start = new Place(tb.Selection.Start.iChar - 1, tb.Selection.Start.iLine); + tb.Selection.SetStartAndEnd(new Place(tb.Selection.Start.iChar - 1, tb.Selection.Start.iLine)); } break; case '\t': @@ -123,11 +123,11 @@ internal static void InsertChar(char c, ref char deletedChar, TextSource ts) for (int i = 0; i < spaceCountNextTabStop; i++) ts[tb.Selection.Start.iLine].Insert(tb.Selection.Start.iChar, new Char(' ')); - tb.Selection.Start = new Place(tb.Selection.Start.iChar + spaceCountNextTabStop, tb.Selection.Start.iLine); + tb.Selection.SetStartAndEnd(new Place(tb.Selection.Start.iChar + spaceCountNextTabStop, tb.Selection.Start.iLine)); break; default: ts[tb.Selection.Start.iLine].Insert(tb.Selection.Start.iChar, new Char(c)); - tb.Selection.Start = new Place(tb.Selection.Start.iChar + 1, tb.Selection.Start.iLine); + tb.Selection.SetStartAndEnd(new Place(tb.Selection.Start.iChar + 1, tb.Selection.Start.iLine)); break; } } @@ -144,7 +144,7 @@ internal static void InsertLine(TextSource ts) else BreakLines(tb.Selection.Start.iLine, tb.Selection.Start.iChar, ts); - tb.Selection.Start = new Place(0, tb.Selection.Start.iLine + 1); + tb.Selection.SetStartAndEnd(new Place(0, tb.Selection.Start.iLine + 1)); ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); } @@ -172,7 +172,7 @@ internal static void MergeLines(int i, TextSource ts) ts[i].AddRange(ts[i + 1]); ts.RemoveLine(i + 1); } - tb.Selection.Start = new Place(pos, i); + tb.Selection.SetStartAndEnd(new Place(pos, i)); ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); } @@ -238,11 +238,11 @@ internal static void InsertText(string insertedText, TextSource ts) { tb.Selection.BeginUpdate(); char cc = '\x0'; - + if (ts.Count == 0) { InsertCharCommand.InsertLine(ts); - tb.Selection.Start = Place.Empty; + tb.Selection.SetStartAndEnd(Place.Empty); } tb.ExpandBlock(tb.Selection.Start.iLine); var len = insertedText.Length; @@ -311,7 +311,7 @@ public override void Undo() tb.Selection.BeginUpdate(); for (int i = 0; i public override void Undo() { - ts.CurrentTB.Selection.Start = new Place(sel.FromX, Math.Min(sel.Start.iLine, sel.End.iLine)); + ts.CurrentTB.Selection.SetStartAndEnd(new Place(sel.FromX, Math.Min(sel.Start.iLine, sel.End.iLine))); ts.OnTextChanging(); InsertTextCommand.InsertText(deletedText, ts); ts.OnTextChanged(sel.Start.iLine, sel.End.iLine); @@ -455,7 +455,7 @@ internal static void ClearSelected(TextSource ts) InsertCharCommand.MergeLines(fromLine, ts); } // - tb.Selection.Start = new Place(fromChar, fromLine); + tb.Selection.SetStartAndEnd(new Place(fromChar, fromLine)); // ts.NeedRecalc(new TextSource.TextChangedEventArgs(fromLine, toLine)); } @@ -512,7 +512,7 @@ public override void Undo() tb.Selection.BeginUpdate(); for (int i = 0; i < ranges.Count; i++) { - tb.Selection.Start = ranges[i].ReplacedRange.Start; + tb.Selection.SetStartAndEnd(ranges[i].ReplacedRange.Start); for (int j = 0; j < ranges[i].ReplaceText.Length; j++) tb.Selection.GoRight(true); ClearSelectedCommand.ClearSelected(ts); @@ -597,12 +597,12 @@ public override void Undo() var iLine = iLines[i]; if(iLine < ts.Count) - tb.Selection.Start = new Place(0, iLine); + tb.Selection.SetStartAndEnd(new Place(0, iLine)); else - tb.Selection.Start = new Place(ts[ts.Count - 1].Count, ts.Count - 1); + tb.Selection.SetStartAndEnd(new Place(ts[ts.Count - 1].Count, ts.Count - 1)); InsertCharCommand.InsertLine(ts); - tb.Selection.Start = new Place(0, iLine); + tb.Selection.SetStartAndEnd(new Place(0, iLine)); var text = prevText[prevText.Count - i - 1]; InsertTextCommand.InsertText(text, ts); ts[iLine].IsChanged = true; @@ -633,12 +633,12 @@ public override void Execute() for(int i = iLines.Count - 1; i >= 0; i--) { var iLine = iLines[i]; - + prevText.Add(ts[iLine].Text);//backward ts.RemoveLine(iLine); //ts.OnTextChanged(ranges[i].Start.iLine, ranges[i].End.iLine); } - tb.Selection.Start = new Place(0, 0); + tb.Selection.SetStartAndEnd(new Place(0, 0)); tb.Selection.EndUpdate(); ts.NeedRecalc(new TextSource.TextChangedEventArgs(0, 1)); diff --git a/FastColoredTextBox/FastColoredTextBox.cs b/FastColoredTextBox/FastColoredTextBox.cs index d7e2a1e9..ae84aca7 100644 --- a/FastColoredTextBox/FastColoredTextBox.cs +++ b/FastColoredTextBox/FastColoredTextBox.cs @@ -145,7 +145,8 @@ public FastColoredTextBox() InitTextSource(CreateTextSource()); if (lines.Count == 0) lines.InsertLine(0, lines.CreateLine()); - selection = new Range(this) {Start = new Place(0, 0)}; + selection = new Range(this); + selection.SetStartAndEnd(new Place(0, 0)); //default settings Cursor = Cursors.IBeam; BackColor = Color.White; @@ -1477,7 +1478,7 @@ public string SelectedText public int SelectionStart { get { return Math.Min(PlaceToPosition(Selection.Start), PlaceToPosition(Selection.End)); } - set { Selection.Start = PositionToPlace(value); } + set { Selection.SetStartAndEnd(PositionToPlace(value)); } } /// @@ -2246,7 +2247,7 @@ public void Navigate(int iLine) { if (iLine >= LinesCount) return; lastNavigatedDateTime = lines[iLine].LastVisit; - Selection.Start = new Place(0, iLine); + Selection.SetStartAndEnd(new Place(0, iLine)); DoSelectionVisible(); } @@ -2591,8 +2592,8 @@ public virtual void Cut() if (Selection.Start.iLine >= 0 && Selection.Start.iLine < LinesCount) { int iLine = Selection.Start.iLine; - RemoveLines(new List {iLine}); - Selection.Start = new Place(0, Math.Max(0, Math.Min(iLine, LinesCount - 1))); + RemoveLines(new List { iLine }); + Selection.SetStartAndEnd(new Place(0, Math.Max(0, Math.Min(iLine, LinesCount - 1)))); } } } @@ -2646,9 +2647,9 @@ public void SelectAll() public void GoEnd() { if (lines.Count > 0) - Selection.Start = new Place(lines[lines.Count - 1].Count, lines.Count - 1); + Selection.SetStartAndEnd(new Place(lines[lines.Count - 1].Count, lines.Count - 1)); else - Selection.Start = new Place(0, 0); + Selection.SetStartAndEnd(new Place(0, 0)); DoCaretVisible(); } @@ -2658,7 +2659,7 @@ public void GoEnd() /// public void GoHome() { - Selection.Start = new Place(0, 0); + Selection.SetStartAndEnd(new Place(0, 0)); DoCaretVisible(); //VerticalScroll.Value = 0; @@ -2839,9 +2840,9 @@ public virtual void AppendText(string text, Style style) try { if (lines.Count > 0) - Selection.Start = new Place(lines[lines.Count - 1].Count, lines.Count - 1); + Selection.SetStartAndEnd(new Place(lines[lines.Count - 1].Count, lines.Count - 1)); else - Selection.Start = new Place(0, 0); + Selection.SetStartAndEnd(new Place(0, 0)); //remember last caret position Place last = Selection.Start; @@ -3022,7 +3023,7 @@ private void InsertVirtualSpaces() Selection.BeginUpdate(); try { - Selection.Start = new Place(lineLength, Selection.Start.iLine); + Selection.SetStartAndEnd(new Place(lineLength, Selection.Start.iLine)); lines.Manager.ExecuteCommand(new InsertTextCommand(TextSource, new string(' ', count))); } finally @@ -4146,7 +4147,7 @@ public virtual void MoveSelectedLinesDown() for (int i = Selection.Start.iLine; i <= Selection.End.iLine; i++) temp.Add(i); RemoveLines(temp); - Selection.Start = new Place(GetLineLength(iLine), iLine); + Selection.SetStartAndEnd(new Place(GetLineLength(iLine), iLine)); SelectedText = "\n" + text; Selection.Start = new Place(prevSelection.Start.iChar, prevSelection.Start.iLine + 1); Selection.End = new Place(prevSelection.End.iChar, prevSelection.End.iLine + 1); @@ -4174,7 +4175,7 @@ public virtual void MoveSelectedLinesUp() for (int i = Selection.Start.iLine; i <= Selection.End.iLine; i++) temp.Add(i); RemoveLines(temp); - Selection.Start = new Place(0, iLine - 1); + Selection.SetStartAndEnd(new Place(0, iLine - 1)); SelectedText = text + "\n"; Selection.Start = new Place(prevSelection.Start.iChar, prevSelection.Start.iLine - 1); Selection.End = new Place(prevSelection.End.iChar, prevSelection.End.iLine - 1); @@ -4553,13 +4554,13 @@ protected void DoAutoIndentChars(int iLine, Regex regex) continue; if (oldSel.Start.iLine == i && oldSel.Start.iChar > cap.Index) - oldSel.Start = new Place(oldSel.Start.iChar + addSpaces, i); + oldSel.SetStartAndEnd(new Place(oldSel.Start.iChar + addSpaces, i)); if (addSpaces > 0) texts[i] = texts[i].Insert(cap.Index, new string(' ', addSpaces)); else texts[i] = texts[i].Remove(cap.Index + addSpaces, -addSpaces); - + changed[i] = true; was = true; } @@ -4708,7 +4709,7 @@ public virtual void DoAutoIndent(int iLine) //insert start spaces if (needToInsert == 0) return; - Selection.Start = new Place(0, iLine); + Selection.SetStartAndEnd(new Place(0, iLine)); if (needToInsert > 0) InsertText(new String(' ', needToInsert)); else @@ -4718,7 +4719,7 @@ public virtual void DoAutoIndent(int iLine) ClearSelected(); } - Selection.Start = new Place(Math.Min(lines[iLine].Count, Math.Max(0, oldStart.iChar + needToInsert)), iLine); + Selection.SetStartAndEnd(new Place(Math.Min(lines[iLine].Count, Math.Max(0, oldStart.iChar + needToInsert)), iLine)); } /// @@ -5566,15 +5567,15 @@ private void OnMouseClickText(MouseEventArgs e) if (Selection.ColumnSelectionMode) { - Selection.Start = PointToPlaceSimple(e.Location); + Selection.SetStartAndEnd(PointToPlaceSimple(e.Location)); Selection.ColumnSelectionMode = true; } else { if (VirtualSpace) - Selection.Start = PointToPlaceSimple(e.Location); + Selection.SetStartAndEnd(PointToPlaceSimple(e.Location)); else - Selection.Start = PointToPlace(e.Location); + Selection.SetStartAndEnd(PointToPlace(e.Location)); } if ((lastModifiers & Keys.Shift) != 0) @@ -5805,11 +5806,11 @@ protected override void OnMouseMove(MouseEventArgs e) Selection.BeginUpdate(); if (Selection.ColumnSelectionMode) { - Selection.Start = place; + Selection.SetStartAndEnd(place); Selection.ColumnSelectionMode = true; } else - Selection.Start = place; + Selection.SetStartAndEnd(place); Selection.End = oldEnd; Selection.EndUpdate(); DoCaretVisible(); @@ -6643,7 +6644,7 @@ public virtual void CollapseBlock(int fromLine, int toLine) int newLine = FindNextVisibleLine(to); if (newLine == to) newLine = FindPrevVisibleLine(from); - Selection.Start = new Place(0, newLine); + Selection.SetStartAndEnd(new Place(0, newLine)); // needRecalc = true; Invalidate(); @@ -6695,7 +6696,7 @@ public virtual void IncreaseIndent() { if (!Selection.ReadOnly) { - Selection.Start = new Place(this[Selection.Start.iLine].StartSpacesCount, Selection.Start.iLine); + Selection.SetStartAndEnd(new Place(this[Selection.Start.iLine].StartSpacesCount, Selection.Start.iLine)); //insert tab as spaces int spaces = TabLength - (Selection.Start.iChar % TabLength); //replace mode? select forward chars @@ -6736,7 +6737,7 @@ public virtual void IncreaseIndent() for (int i = from; i <= to; i++) { if (lines[i].Count == 0) continue; - Selection.Start = new Place(startChar, i); + Selection.SetStartAndEnd(new Place(startChar, i)); lines.Manager.ExecuteCommand(new InsertTextCommand(TextSource, new String(' ', TabLength))); } @@ -6947,7 +6948,7 @@ public virtual void InsertLinePrefix(string prefix) int spaces = GetMinStartSpacesCount(from, to); for (int i = from; i <= to; i++) { - Selection.Start = new Place(spaces, i); + Selection.SetStartAndEnd(new Place(spaces, i)); lines.Manager.ExecuteCommand(new InsertTextCommand(TextSource, prefix)); } Selection.Start = new Place(0, from); @@ -7123,7 +7124,7 @@ public Range GetBracketsRange(Place placeInsideBrackets, char leftBracket, char if (range.CharAfterStart == rightBracket) counter--; if (counter == 1) { - range.Start = new Place(range.Start.iChar + (!includeBrackets ? 1 : 0), range.Start.iLine); + range.SetStartAndEnd(new Place(range.Start.iChar + (!includeBrackets ? 1 : 0), range.Start.iLine)); leftBracketPosition = range; break; } @@ -7501,7 +7502,7 @@ public void OpenFile(string fileName, Encoding enc) IsChanged = false; throw; } - Selection.Start = Place.Empty; + Selection.SetStartAndEnd(Place.Empty); DoSelectionVisible(); } @@ -7671,7 +7672,7 @@ void ISupportInitialize.BeginInit() void ISupportInitialize.EndInit() { OnTextChanged(); - Selection.Start = Place.Empty; + Selection.SetStartAndEnd(Place.Empty); DoCaretVisible(); IsChanged = false; ClearUndo(); @@ -7737,7 +7738,7 @@ private void DoDragDrop_old(Place place, string text) { Selection.BeginUpdate(); // Insert text - Selection.Start = place; + Selection.SetStartAndEnd(place); InsertText(text); // Select inserted text Selection = new Range(this, place, Selection.Start); @@ -7844,7 +7845,7 @@ protected virtual void DoDragDrop(Place place, string text) { Selection.BeginUpdate(); // Insert text - Selection.Start = place; + Selection.SetStartAndEnd(place); InsertText(text); // Select inserted text Selection = new Range(this, place, Selection.Start); @@ -8004,7 +8005,7 @@ protected override void OnDragOver(DragEventArgs e) if (e.Data.GetDataPresent(DataFormats.Text)) { Point p = PointToClient(new Point(e.X, e.Y)); - Selection.Start = PointToPlace(p); + Selection.SetStartAndEnd(PointToPlace(p)); if (p.Y < 6 && VerticalScroll.Visible && VerticalScroll.Value > 0) VerticalScroll.Value = Math.Max(0, VerticalScroll.Value - charHeight); diff --git a/FastColoredTextBox/FindForm.cs b/FastColoredTextBox/FindForm.cs index b20282d5..aba3f058 100644 --- a/FastColoredTextBox/FindForm.cs +++ b/FastColoredTextBox/FindForm.cs @@ -62,7 +62,7 @@ public virtual void FindNext(string pattern) // if (range.Start >= startPlace && startPlace > Place.Empty) { - tb.Selection.Start = new Place(0, 0); + tb.Selection.SetStartAndEnd(new Place(0, 0)); FindNext(pattern); return; } diff --git a/FastColoredTextBox/Range.cs b/FastColoredTextBox/Range.cs index 2faabd9f..33038aed 100644 --- a/FastColoredTextBox/Range.cs +++ b/FastColoredTextBox/Range.cs @@ -157,9 +157,9 @@ public void SelectAll() { ColumnSelectionMode = false; - Start = new Place(0, 0); + SetStartAndEnd(new Place(0, 0)); if (tb.LinesCount == 0) - Start = new Place(0, 0); + SetStartAndEnd(new Place(0, 0)); else { end = new Place(0, 0); @@ -177,7 +177,7 @@ public Place Start get { return start; } set { - end = start = value; + start = value; preferedPos = -1; OnSelectionChanged(); } @@ -728,6 +728,12 @@ internal void GoEnd(bool shift) preferedPos = -1; } + /// + /// Setter changing both, the Start and End property to the same value + /// + /// The new place + public void SetStartAndEnd(Place value) { End = Start = value; } + /// /// Set style for range /// @@ -1214,7 +1220,7 @@ public Range GetFragment(Style style, bool allowLineBreaks) var mask = tb.GetStyleIndexMask(new Style[] { style }); // Range r = new Range(tb); - r.Start = Start; + r.SetStartAndEnd(Start); //go left, check style while (r.GoLeftThroughFolded()) { @@ -1229,7 +1235,7 @@ public Range GetFragment(Style style, bool allowLineBreaks) } Place startFragment = r.Start; - r.Start = Start; + r.SetStartAndEnd(Start); //go right, check style do { @@ -1252,7 +1258,7 @@ public Range GetFragment(Style style, bool allowLineBreaks) public Range GetFragment(string allowedSymbolsPattern, RegexOptions options) { Range r = new Range(tb); - r.Start = Start; + r.SetStartAndEnd(Start); Regex regex = new Regex(allowedSymbolsPattern, options); //go left, check symbols while (r.GoLeftThroughFolded()) @@ -1265,7 +1271,7 @@ public Range GetFragment(string allowedSymbolsPattern, RegexOptions options) } Place startFragment = r.Start; - r.Start = Start; + r.SetStartAndEnd(Start); //go right, check symbols do { diff --git a/FastColoredTextBox/ReplaceForm.cs b/FastColoredTextBox/ReplaceForm.cs index 2d7d7c1d..51c01f0c 100644 --- a/FastColoredTextBox/ReplaceForm.cs +++ b/FastColoredTextBox/ReplaceForm.cs @@ -85,7 +85,7 @@ public bool Find(string pattern) } if (range.Start >= startPlace && startPlace > Place.Empty) { - tb.Selection.Start = new Place(0, 0); + tb.Selection.SetStartAndEnd(new Place(0, 0)); return Find(pattern); } return false; @@ -155,7 +155,7 @@ private void btReplaceAll_Click(object sender, EventArgs e) if (ranges.Count > 0) { tb.TextSource.Manager.ExecuteCommand(new ReplaceTextCommand(tb.TextSource, ranges, tbReplace.Text)); - tb.Selection.Start = new Place(0, 0); + tb.Selection.SetStartAndEnd(new Place(0, 0)); } // tb.Invalidate(); diff --git a/Tester/PowerfulCSharpEditor.cs b/Tester/PowerfulCSharpEditor.cs index af7fa332..3de6b898 100644 --- a/Tester/PowerfulCSharpEditor.cs +++ b/Tester/PowerfulCSharpEditor.cs @@ -824,7 +824,7 @@ private void cloneLinesToolStripMenuItem_Click(object sender, EventArgs e) //get text of selected lines string text = Environment.NewLine + CurrentTB.Selection.Text; //move caret to end of selected lines - CurrentTB.Selection.Start = CurrentTB.Selection.End; + CurrentTB.Selection.SetStartAndEnd(CurrentTB.Selection.End); //insert text CurrentTB.InsertText(text); } @@ -840,7 +840,7 @@ private void cloneLinesAndCommentToolStripMenuItem_Click(object sender, EventArg //comment lines CurrentTB.InsertLinePrefix("//"); //move caret to end of selected lines - CurrentTB.Selection.Start = CurrentTB.Selection.End; + CurrentTB.Selection.SetStartAndEnd(CurrentTB.Selection.End); //insert text CurrentTB.InsertText(text); //end of autoUndo block diff --git a/Tester/PowerfulSample.cs b/Tester/PowerfulSample.cs index d103c0a2..e07daa64 100644 --- a/Tester/PowerfulSample.cs +++ b/Tester/PowerfulSample.cs @@ -256,7 +256,7 @@ void GoLeftBracket(FastColoredTextBox tb, char leftBracket, char rightBracket) if (counter == 1) { //found - tb.Selection.Start = range.Start; + tb.Selection.SetStartAndEnd(range.Start); tb.DoSelectionVisible(); break; } @@ -279,7 +279,7 @@ void GoRightBracket(FastColoredTextBox tb, char leftBracket, char rightBracket) if (counter == -1) { //found - tb.Selection.Start = range.Start; + tb.Selection.SetStartAndEnd(range.Start); tb.Selection.GoRightThroughFolded(); tb.DoSelectionVisible(); break; diff --git a/TesterVB/BookmarksSample.resx b/TesterVB/BookmarksSample.resx index 73dd7f6f..cfc0d3ec 100644 --- a/TesterVB/BookmarksSample.resx +++ b/TesterVB/BookmarksSample.resx @@ -153,7 +153,7 @@ Public Class BookmarksSample Dim id As Integer = bookmarks(iBookmark) For i As Integer = 0 To fctb.LinesCount - 1 If fctb(i).UniqueId = id Then - fctb.Selection.Start = New Place(0, i) + fctb.Selection.SetStartAndEnd(New Place(0, i)) fctb.DoSelectionVisible() fctb.Invalidate() Exit For