473,394 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Formatting 'text' in RichTextBox ...

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

Nov 15 '05 #1
2 17261
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"

"Hariharan S" <fr********@televital.com> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
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


Nov 15 '05 #2
"Hariharan S" <fr********@televital.com> wrote in message
news:uq**************@TK2MSFTNGP12.phx.gbl...
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
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Neil | last post by:
Is there an editable RTF textbox control which allows the user to apply bold, italic, etc.? I tried the Microsoft Rich Textbox Control, but there doesn't seem to be a way to allow the user to...
0
by: Hariharan S | last post by:
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...
0
by: Radu.Micu | last post by:
I have a RichTextBox on my form and I want to save the text that a user writes into it in a AccessDB but I want to save the formatted text not only plain txt I have seen in some programs that the...
1
by: Kevin | last post by:
Hello, Does anyone know how to implement find and replace in a RichTextBox in a way that does not lose the text formatting? As a first attempt I tried rtb.Rtf.Replace(sFindText,...
2
by: Chris Rollock | last post by:
on msdn: "you can initialize the Rtf property to a string that contains the text to display, including the RTF codes that determine how the text should be formatted." Nowhere can I find an example...
0
by: ronchese | last post by:
Hello All. I'm using the RichTextBox control to show text to user that can do the primary font formatting: fontname, size, color, bold, italic and underline. Unlike the RichTextBox used in VB...
2
by: Mystique | last post by:
Hello Is there any way to format text with tags (something like html tags) in a RichTextBox? Something similar to this: string aStr; aStr = "<b>this is bold</bthis is normal"; ...
3
by: michael sorens | last post by:
The documentation for the RichTextBox is sketchy at best. I want to do a very simple task but I cannot find information on this. I am using a RichTextBox as an output window. Some text I want to...
2
by: drfreaky | last post by:
Hello, I want to use a richtextbox for logging status messages. I have three kind of message types and want to use different formatting for them. My problem is, I change the color, add the text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.