tags:

views:

28

answers:

1

Hi SO, I'm thinking of developing a more efficient version of the Rich Text format but I need to know a little about Syntax Highlighting and Syntax Extraction.

Like when reading the file, read all the {Property Boxes} and use them in a RichTextBox. Ex:
{C=0000FF}Hello world!{/C} Prints "Hello world!" in red.

This would also be good to figure out because I am also building acode editor for a very simple version of Python and color codded text would make things easier and seems pretty standard.

A: 

There's a codeproject article about this called Syntax highlighting textbox written in C# which might give you some pointers.

And in case you're going to use a RichTextBox I'd suggest this blog post Some RichTextBox tricks .

It might be worth trying to get hold of the book Dissecting a C# Application: Inside SharpDevelop which has a chapter called Chapter 9: Syntax Highlighting (quite old book but might be able to get a second hand copy).

ho1
Wow thank you I will look into this! before I was stuck using for each word in rtb and the crazy scrolling, flashing, etc.In fact the hardest part of formatting code in a rtb is selecting all the text between two quotes.Have any specific tips for that?
Yiu Korochko
@Yiu: I've not used it in a long time but I seem to remember it was just to use the `Select` method with the start and end postions, as seen here: http://msdn.microsoft.com/en-us/library/xc4fh98s.aspx, or do you mean something else?
ho1
@ho1: I think this may be it but I'm not sure quite yet, I'll have to test it out. But I mean as if I typed: $ mikou = Character('魅稿', color="#00FF0F") or unk "\n何か変な..." the "#00FF0F" or "\n何か変な..." (including quotations) would be selected. This brings variables into account and this is specifically the most difficult part.Another example would be like in VB.NET, when I type an apostrophe and the rest of the line turns green for a comment, specifically selecting between the apostrophe and the end of the line.
Yiu Korochko
The regular Select+SelectLength method is okay for smaller field of text, but definately not for large amounts of text. I've looked into a few things and people are saying I should parse via an XML document containing the coloring rules? I now have a full question for it, but for the most part, I'm still a little stuck. In all other aspects, the program is coming along excellently.
Yiu Korochko