473,407 Members | 2,315 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,407 software developers and data experts.

j@hnny

I've got a procedure that is responsible for performing the following operations on a richtextbox
1) determining what parts of the text to forma
2) formatting specific ranges of text a specific color

I need to do this whenever the contents of the richtextbox change. The algorithm is quite fast as I have built in some speed saving optimizations, but i need to do some more, I was wondering if anybody could give me any suggestions? So far, I've coded it to
* - retrieve information about all ranges 'as of now' but only setting the format of ones that are new / only unsetting the format of ones that were there but aren't no
* - only set the format of ranges that are visible. For this, I use the message EM_GETFIRSTVISIBLELINE to get the first visible line, and the line count by dividing the height by the height of a line (got by GetTextMetrics). But then I need to do a rescan of ranges to format on vscroll aswell as on textchange, which is a bit bad as it's slow when you scroll

I was thinking of having some sort of 'lazy updater' type thing that either runs for, say, 100 milliseconds each second, or in a different thread, to update the RTB for the ranges that are off the visible range once all the others have been done, but I can't get my head round how to handle the synchronicity with the fact that when the richtextbox's contents change, the ranges will change too. Should I consider this a thing that takes 'a long time' to happen? Or can anyone else lend a hand with the obviously huge amount of sideways thinking I'm having to do!!

It's for a syntax highlighting control, right now I'm just trying to get it to be able to parse c-style block comments, line comments and quotes (red.

Any ideas on performance in this area
Have posted to C++ groups as although I am writing the app in c# I am non too averse to turn my hand to c++

Thanks
Nov 16 '05 #1
2 1206
I see we were thinking on the same thing ;-)
but, as you said, when scrolling -> it is a total disaster!
the quickest way is to color all text at once(when opening) or when
riting - line by line... (i think...)
maybe this will help:

http://www.c-sharpcorner.com/Code/20...ntaxEditor.asp

Nov 16 '05 #2
ah, cheers - looks good i'll check it out.

"Bad_Kid" <RE*******************@yahoo.co.uk> wrote in message
news:c9**********@bagan.srce.hr...
I see we were thinking on the same thing ;-)
but, as you said, when scrolling -> it is a total disaster!
the quickest way is to color all text at once(when opening) or when
riting - line by line... (i think...)
maybe this will help:

http://www.c-sharpcorner.com/Code/20...ntaxEditor.asp

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

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.