is there a way?

  • Thread starter Thread starter Bad_Kid
  • Start date Start date
B

Bad_Kid

To change text's color without selecting it - (example, when a button is
pressed to change color of the characters from 4th to 6th)?? (richTextBox)
- 'cause the only way I know is to select that string and then to change
color of selection...

- can it be done without:
this.richTextBox1.Select(4,2);
this.richTextBox1.SelectionColor = Color.Black;

thnx!
 
Hi Bad_Kid,

The trick is to remember the cursor position before changing the text, and
restore it afterwards.

oldPosition = SelectionStart
Select(4,2);
SelectionColor = Color.Black;
SelectionLength = 0;
SelectionStart = oldPosition;

Happy coding!
Morten Wennevik [C# MVP]
 
thanks, I did that, but sometimes (not every time) text blinks (select,
deselect) and I would like to avoid that??
 
I'm not sure how to avoid the blinking. Maybe you need to use DrawString
to get rid of that and keep track of positions and line numbers yourself..

Happy coding!
Morten Wennevik [C# MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top