Jump to content
  • Advertisement
Sign in to follow this  
paic

[.net] RichTextBox and syntax highlighting

This topic is 3723 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to implement a user control which inherit from a RichTextBox and implement various options, such as syntax highlighting. For this part, I don't really know how to do it. At first, I tried to override the OnTextChanged method, and do my stuff as the user type text. Problem occurs when pasting text. And it rapidely became very complex to handle new highlighting rules :s Then I thought I could use regular expression. But the problem is that I have to use them on the whole text, and I have the feeling it would be slow. Any suggestion ? Or if you already used Regex with C#, is it fast enough so that it wouldn't be a problem for texts a 100's lines ? Thx.

Share this post


Link to post
Share on other sites
Advertisement
Using a rich text box for syntax highlighting is a fairly large exercise in pain. Consider using an existing syntax highlighting control like scintilla.

Share this post


Link to post
Share on other sites
Yes, I already noticed that it's not really simple :)
And I also did find a few existing controls (not the one you linked though :))
But that doesn't really answer my question. Doing this is 50% for personal knowledge / 50% for work. So if it's feasible with regular expressions, I'd like to give it a try.
I just need to know if regular expression with C# are fast enough to handle a few 100s of lines :)

Share this post


Link to post
Share on other sites
It depends on how often you use the regex, how complicated the regex is and how powerful the computer running the code is. Basically, the only way to know for sure is to try it out and see if it'll work.

Share this post


Link to post
Share on other sites
I'm trying to obtain something similar for our game interface, the main difference being I have to render everything using a DX based engine; it turned out to be a rather complex problem as you've already noticed.

For starters, you could have a look at SharpDevelop and its code. I think there's a wealth of informations about creating a formattable textbox from scratch. There's a lot of things to take in account, I wouldn't be able to summarize them in a post, so I suggest to try and get a copy of the SharpDevelop book.

Hope this helps.

Share this post


Link to post
Share on other sites
There are a few articles on this topic on http://www.codeproject.com but as already said, working with RichTextBox can become quite hard if you want to add functionalities. I began to wrote a simple text editor but if I wanted to start that project again, I would get an opensource editor next time :-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!