469,950 Members | 1,456 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Postition RichTextBox to specified character position

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.

Oct 17 '08 #1
5 5814
On Fri, 17 Oct 2008 05:48:29 -0700, Andrus <ko********@hot.eewrote:
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.
Define "current position property".

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".

Pete
Oct 17 '08 #2
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.

Oct 17 '08 #3
On Fri, 17 Oct 2008 12:50:35 -0700, Andrus <ko********@hot.eewrote:
[...]
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 ?
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.

Pete
Oct 17 '08 #4
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.

Oct 18 '08 #5
On Sat, 18 Oct 2008 13:53:15 -0700, Andrus <ko********@hot.eewrote:
Thank you very much.
I havent ever programmed richtextbox.
Where to find some sample which implements this ?
Are you asking about the icon specifically, or just formatting in general?

I don't actually know whether you can in fact easily insert an image into
a RichTextBox; that is, I don't know of any specific methods on the
RichTextBox class (you can always edit the RTF directly, of course). Even
if you can, note that the example you gave for a blinking icon is not
inherent to the image; the ErrorProvider class starts a timer when you set
the error, and handles the blinking explicitly, outside the image data
itself. You would probably have to do something similar when trying to
cause an image in a RichTextBox to blink.

But as far as formatting in general goes, MSDN has a number of code
samples related to using the RichTextBox class, including examples of how
to set formatting using the various format-related properties and methods
on the class. As long as you are not dead-set on having a blinking image
in your RichTextBox, it should be reasonably straightforward for you to
implement what you want using the MSDN docs.

http://msdn.microsoft.com/en-us/libr...chtextbox.aspx

Pete
Oct 18 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by James dean | last post: by
6 posts views Thread by Rachel Suddeth | last post: by
8 posts views Thread by Dennis | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.