473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 6046
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris | last post by:
Using VB6. With a RichTextbox, I can get the position of the character under the mouse pointer with an API call like: SendMessage(hWnd, EM_CHARFROMPOS, 0&, Pointl) by passing the mouse x,y...
1
by: Arlyn_L | last post by:
Can someone please explain why I get a different result when using the GetLineFromCharIndex method on the last char in the Text property and the Lines.Length property? MainForm_gedcomTextBox is...
0
by: James dean | last post by:
In this program i set the RichTextBox property SelectionStart in order to move the caret(cursor) onto the next character. I have a loop to do this but unfortunately this is very slow. How would i...
6
by: Rachel Suddeth | last post by:
I have the index of a line in the Lines array of a RichTextBox. I would like to have it scroll so that line displays at the top. Is there no way to do this? The only way I can see to make it...
0
by: Sakharam Phapale | last post by:
Hi All, How to get the starting and end character position of the given line no in RichTextBox? I have written following code but it takes more time. Is there any RichTextBox function or API...
2
by: Al | last post by:
Hi, Is there any way to replace a character at a position? Without cussing the RichTextBox to scroll. For example the following code will replaces the by removing but the side effect is that it...
8
by: Dennis | last post by:
How can I tell if the Insert Mode is on or off? -- Dennis in Houston
0
by: Vincent | last post by:
Dear all, I have implemented a class to export the content of RichTextBox to image in WYSISYG mode so that line breaks on the screen are the same as exported. C# Code: public struct...
2
by: marfi95 | last post by:
Hi all, I am trying to change the color of text that the user sees when they are editing a richtextbox. This is the code I am using in the TextChanged method of RichTextBox control. Dim...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.