Changing the font of text in richtextbox without affecting thepresent colour of text

G

Gouri.Mahajan7

Hello,

I want to change the font of the text in richtextbox without
affecting
the colour of text. I want some text to be printed in different
colours. When I try to change the font of the text the colour is
turned to black. How to solve this problem.??


Thanks in advance.


Regards,
Gouri.
 
S

SMJT

Hello,

I want to change the font of the text in richtextbox without
affecting
the colour of text. I want some text to be printed in different
colours. When I try to change the font of the text the colour is
turned to black. How to solve this problem.??

Thanks in advance.

Regards,
Gouri.

Hi Gouri,

I don't think you are doing anything wrong, the only way I know to
change the font color is to use the SelectionFont Property on the
richtextbox.
richTextBox1.SelectionFont = new Font("Courier New", 10,
FontStyle.Bold);
richTextBox1.SelectAll();
richTextBox1.SelectionColor = Color.Red;

When you change Font associated with the richtext box, this the
selectfont is reset/changed;
richTextBox1.Font = new Font("Arial", 10, FontStyle.Regular);

If all you want to do is change al the text to red then the above will
work fine, however if you need to keep multiple different colrs then
you need to parse the text and reset the selectfont, using the
SelectionStart and SelectionLength properties on the richtext box,
which is obviously a bit more painful.

SMJT
 

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

Top