views:

512

answers:

1

Consider my windows application built using C# VS 2005 displays certain contents in a multi lined text box. Now when i add some new text, it should appear in a different colour. i.e i need to differentiate the text which gets displayed when my project is run and the text that i enter in the text box. how can i do this.?

+6  A: 

The plain TextBox control doesn't support multiple colours, fonts etc.

I suspect you'll need to use a RichTextBox instead. You can then set the SelectionColor property to change the colour of the currently selected text or text inserted at the current insertion point.

I should add that after a few quick experiments, I've found that setting the selection colour and then immediately appending text programmatically doesn't work quite as straightforwardly as I'd hoped. Maybe another answer will explain why :) However, text entered by the user certainly appears in the new colour immediately...

Jon Skeet
Thanks for your answer and i will be appending or inserting text in the rich text box manually and not programatically. This text which i insert should get displayed in a different colour.
pragadheesh