Formatting 'text' in RichTextBox ...

H

Hariharan S

Hi Guys,

I have a string, say "Hello World" and would like to format the way I want
to (say, wanna have the Hello to be bold italic and the World to be of font
size 14 or so) and put it in the RichTextBox, I created.

Just want to paste or write this string to the RichTextBox; what command
should I use? I used the following command and it did not help ...

richTextBox.SelectionFont = <some font selected>
richTextBox.Text = "Hello World";

Even the Paste() command is of no help as it writes to the RichTextBox in
black color with the default font (even though the color and the font I
applied are totally different. Any help on this is greatly appreciated.
Thanks in advance

Regards,
Hariharan S
 
R

Robert Jacobson

The SelectionFont property isn't working because there isn't any selection.
Instead, just use the .Font property:

RichTextBox1.Font = New System.Drawing.Font("Times New Roman", 20)
RichTextBox1.Text = "Hello World"
 
K

Ken Arway

Hariharan S said:
should I use? I used the following command and it did not help ...

richTextBox.SelectionFont = <some font selected>
richTextBox.Text = "Hello World";

You have to use the "SelectedText" property:

richTextBox1.SelectionFont = <some font>;
richTextBox1.SelectionColor = Color.<some color name>;
richTextBox1.SelectedText = "Hello";

richTextBox1.SelectionFont = <some other font>;
richTextBox1.SelectionColor = Color.<some other color name>;
richTextBox1.SelectedText = "World";

Ken
 

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