How to position cursor at some position in RichTextBox
-
I use Winforms RichTextBox control to edit scripts. Scripts are plain ascii texts. When error occurs, script engine returns character position of error in code as integer. How to position cursor to this character position ? RichTextBox does not have current position property.
Andrus
-
I use Winforms RichTextBox control to edit scripts. Scripts are plain ascii texts. When error occurs, script engine returns character position of error in code as integer. How to position cursor to this character position ? RichTextBox does not have current position property.
Andrus
Hi Andrus, I got 2 options:
richTextBox1.SelectionStart = 50; richTextBox1.SelectionLength = 0; richTextBox1.Select(60, 0);
The second property/attribute that I´ve set 0 is the length of the selection, if you want to select some text, you can send the length of the selection, but if you don´t want to select, send 0 and then the cursor was positioned in the index.
----- LeandroAB
-
I use Winforms RichTextBox control to edit scripts. Scripts are plain ascii texts. When error occurs, script engine returns character position of error in code as integer. How to position cursor to this character position ? RichTextBox does not have current position property.
Andrus
Set the selection start to the character position you want, and the selection length to 0
richTextBox1.SelectionStart = position;
richTextBox1.SelectionLength = 0;Simon
-
Hi Andrus, I got 2 options:
richTextBox1.SelectionStart = 50; richTextBox1.SelectionLength = 0; richTextBox1.Select(60, 0);
The second property/attribute that I´ve set 0 is the length of the selection, if you want to select some text, you can send the length of the selection, but if you don´t want to select, send 0 and then the cursor was positioned in the index.
----- LeandroAB
:laugh: Beat me to it. Nice one.
Simon