Hi guys,

I want to add syntax highlighting to my text editor, and I came up with ColorCode library at this address http://colorcode.codeplex.com but I couldn't load the parsed code into richTextBox object using rtb property. The following code returns parsed html code.

using ColorCode;

string sourceCode = File.ReadAllText(@"/path/to/source/file");

string colorizedSourceCode = new CodeColorizer().Colorize(sourceCode, Languages.CSharp);

So, is there any method to display the parsed html code into editor correctly.

Thanks guys anyway, and any help appreciated.

[EL-Prince]

Recommended Answers

All 5 Replies

RichTextBox control uses RTF color codes. What color coding does that library use? I couldn't find any documentation for the library from CodePlex.

Documentation wasn't any help. I found only the following example:

using ColorCode;

string sourceCode = File.ReadAllText(@"/path/to/source/file");

string colorizedSourceCode = new CodeColorizer().Colorize(sourceCode, Languages.CSharp);

which you were using too.

Since there isn't any better examples, try to use RichTextBoxes Text property: RichTextBox.Text = colorizedSourceCode; If it doesn't help, you should atleast be able to see what kind of color codes are stored in colorizedSourceCode

HTH

the colorizedSourceCode has the code warped in html tags to keep its format, the question now how to make richtextbox object to accept this syntax back again??

Thanks

I downloaded the component for testing. I dropped a webbrowser control to a form and it displayed the syntax-colored source code ok. It seemed to me that the library is only for syntax highlighting, and I didn't find any way to use it as a part of the programming editor. A great tool for dumping source code snippets to web pages and that's all (IMHO).

the code warped in html tags to keep its format, the question now how to make richtextbox object to accept this syntax back again?

Only by converting HTML to RTF. There are libraries/components for html->rtf->html conversions. You'll find them with a little googling.

The second solution would be to extend the library to produce rtf-coded text. Component has ColorCode.Formatting.HtmlFormatter class that implements ColorCode.IFormatter interface. It could be possible to write ColorCode.Formatting.RtfFormatter which implements IFormatter interface. But that would require the documentation of the rtf-format (available in the internet AFAIK) and plenty of time :)

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.