Coloring string when painting text
-
Hey guys, I'm trying to create a control which simply colors certain words in a string, when printed onto a control. For example: "This is a test statement to test the highlighting's ability to test." In this statement, when printed on a control, I need all the words "test" being highlighted in say, blue, while the rest of the string remains the regular color. I've been trying to figure out an effective way of doing this for a long time. I have a graphics buffer, double buffering and some intensive graphic's performance boosting codes in place, but i'm trying not to implement nests of loops just to highlight words. Can anyone point me in the right direction with this? I've been using Regex to find patterns (replacing 'test' with '\C[0,0,255]test') and then converting the '\C[x,y,z]' into a color and looping through word by word, and nesting inside letter by letter, but this is too intensive and simply won't work. Thanks :)
-
Hey guys, I'm trying to create a control which simply colors certain words in a string, when printed onto a control. For example: "This is a test statement to test the highlighting's ability to test." In this statement, when printed on a control, I need all the words "test" being highlighted in say, blue, while the rest of the string remains the regular color. I've been trying to figure out an effective way of doing this for a long time. I have a graphics buffer, double buffering and some intensive graphic's performance boosting codes in place, but i'm trying not to implement nests of loops just to highlight words. Can anyone point me in the right direction with this? I've been using Regex to find patterns (replacing 'test' with '\C[0,0,255]test') and then converting the '\C[x,y,z]' into a color and looping through word by word, and nesting inside letter by letter, but this is too intensive and simply won't work. Thanks :)
Hi, a simple way to get this would be by using a RichTextBox; you can add text, select parts of it, and modify attributes (such as ForeColor) for selected text. another way could be to have a Panel and paint all the text yourself in the Paint handler, using Graphics.DrawString with a Font and a Brush (hence color) you choose. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
Hi, a simple way to get this would be by using a RichTextBox; you can add text, select parts of it, and modify attributes (such as ForeColor) for selected text. another way could be to have a Panel and paint all the text yourself in the Paint handler, using Graphics.DrawString with a Font and a Brush (hence color) you choose. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
Well i'm trying to avoid using an RTFBox. It has some handy functions, but i'm really trying to focus on using this control without being dependant on the RTFBox. I might just need to find a much more efficient way to process the highlighted words in a string of text.
-
Well i'm trying to avoid using an RTFBox. It has some handy functions, but i'm really trying to focus on using this control without being dependant on the RTFBox. I might just need to find a much more efficient way to process the highlighted words in a string of text.
when I create a text editor, I use a Panel and draw everything myself. Syntax coloring means looking for keywords and some delimiters and using some colors. For an IDE, texts are line oriented, so things are pretty much local; and the big trick is to only compute lines that are visible, which is say 50 lines out of a file that could span hundreds or thousands of lines. If you want more specific help, you'll have to provide some concrete information; so far you have been very vague! FYI: I avoid Regex when performance is important; IMO most of the time Regex offers comfort at the expense of speed. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.