Sign in to follow this  
Super Llama

Problem with RichTextBox control (VB.NET)

Recommended Posts

I created my own programming language for my game engine, and I made an automatic Color-Coder for it. I'm using VB.NET and the RichTextBox control. I've been formatting it by setting the SelectionColor variable, then the SelectionText, which works great. My problem is this: Once you get a whole lot of lines, it has a HUGE delay between each letter, and it scrolls all the way up and all the way down again. I've tried numorous workarounds, and nothing worked. I'm thinking if there was an easier way to set the colors of each letter, I could lessen the delay considerably. Can someone please help me?

Share this post


Link to post
Share on other sites
So by the sounds of it the control is painting ALL the text with your colour formatting every time you add more text to it rather than just adding a little bit more text with the colour formatting for that bit?

This doesn't sound right to me, how are you adding the text to the control? Are you subscribing to an event from the control (I think something is fired every time text is added to it) and then parsing the entire text to add colour formatting? If you post some code I'll take a look at it for you (unless someone else knows why this is happening?)

Also, stick a SuspendLayout(); ResumeLayout(); call before and after your parsing method and see if this helps in any way.

James

Share this post


Link to post
Share on other sites
Yes, it reformats the code every time you add a letter. That's the only way I can see to do it, but I should probably make it so it deletes the last typed character and then replaces it with a formatted version. Thanks for the ideas, and I'll try the SuspendLayout() thing. Lol never heard of that function before =D

EDIT: I tried the SuspendLayout, and it didn't do anything :(
I'm going to try the char-at-a-time approach now.

EDIT AGAIN:
LOL there was a WIERD error... I typed something in to it, and it typed the same thing backwards after the insertion point :S

EDIT AGAIN:
UGH now when I press backspace it types a square XD

EDIT AGAIN:
UGH it's still not working... maybe I should just forget about the color-coding...

[Edited by - Super Llama on May 15, 2008 12:32:59 PM]

Share this post


Link to post
Share on other sites
Hey, I don't think you need to give up on this - sounds like an interesting problem.

You definately need to make the text area that the user is writting into a User Control - base it on a RichTextBox and give it the ability to parse the text based on your language. I think your only problem here is that in your previous attempt you were going through every word in the RichTextBox - if you could do the check / colouring every time a word was entered without having to go through every piece of text then it would be fine.

I might see what I can come up with and post some code.

James

Share this post


Link to post
Share on other sites
I've been thinking about this problem and I think the answer has come to me!

In a RichTextBox you have a property which is a string and represents the Rich Text Format of the box (RichTextBox.Rtf). This string contains all the RTF formatting of your text and you should be able to edit this to colour code your text. I don't know much about the RTF but a quick Google found me this (the RTF specification) and this (which is some C# code that does exactly what you want!). As I said the second link looks like it does exactly what you want, you'll just need to port the code (should be easy).

Hope that helps!

James

NOTE: Just found this too - not too sure what it is but it's about parsing text in a RichTextBox in VB.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this