Postition RichTextBox to specified character position

  • Thread starter Thread starter Andrus
  • Start date Start date
A

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.
 
Pete,
Like TextBox, RichTextBox has the SelectionStart and SelectionLength
properties, which can be used to position the text cursor within the
control. Alternatively, you can use the Select() method.

If that's not what you're looking for, it would be helpful if you could be
more specific about what you mean by "current position".

Thank you very much. Current position is character index in source text. I
used Select() and this worked.

However the bad line where cursor is moved is not visible well.

How to make this line more visible, e.q add exclamation sign before line
like in DataGridView or
make bold or higlight or underline it in some special way
like in VS so that this is removed when cursor moves to next line ?

Errorprovider icon blinks nicely so this would be nice to use.

However I havent found a way to put errorprovider icon before Select() by
positon line in RichTextBox.

Andrus.
 
Pete,
You can do whatever you want, as long as it's supported within the
RichTextBox formatting ability. Just apply whatever formatting or insert
whatever new text or graphics you want to provide the highlighting. You
can handle the SelectionChanged event to track when the text cursor (also
known as "caret") is moved, so that you know when to remove whatever
formatting change you've applied.

Thank you very much.
I havent ever programmed richtextbox.
Where to find some sample which implements this ?

Andrus.
 
Back
Top