473,792 Members | 2,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sel ectionFont = <some font selected>
richTextBox.Tex t = "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 17289
The SelectionFont property isn't working because there isn't any selection.
Instead, just use the .Font property:

RichTextBox1.Fo nt = New System.Drawing. Font("Times New Roman", 20)
RichTextBox1.Te xt = "Hello World"

"Hariharan S" <fr********@tel evital.com> wrote in message
news:uq******** ******@TK2MSFTN GP12.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.Sel ectionFont = <some font selected>
richTextBox.Tex t = "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********@tel evital.com> wrote in message
news:uq******** ******@TK2MSFTN GP12.phx.gbl...
should I use? I used the following command and it did not help ...

richTextBox.Sel ectionFont = <some font selected>
richTextBox.Tex t = "Hello World";


You have to use the "SelectedTe xt" property:

richTextBox1.Se lectionFont = <some font>;
richTextBox1.Se lectionColor = Color.<some color name>;
richTextBox1.Se lectedText = "Hello";

richTextBox1.Se lectionFont = <some other font>;
richTextBox1.Se lectionColor = Color.<some other color name>;
richTextBox1.Se lectedText = "World";

Ken
Nov 15 '05 #3

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

Similar topics

2
5838
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 change the formatting while typing text. Is there such a beast? Thanks, Neil
0
1708
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 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>
0
1397
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 db table has 2 columns one for the plain txt and one for some enconding I do not know but I know for certain that in that column all formatting are hold, is there a way to do this? Because to insert the rtf format to the DB is not realy efficient...
1
7943
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, sReplaceText) , but that's no good since .Rtf includes all the formatting codes, and .Replace will change richtext codes that shouldn't be changed.
2
5493
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 on how to do this. I'm taking data from an xml file as a string, and I want to display it in a richtextbox with formatting depending on what it is I'm looking at. All I need is an example of how to directly append (rather than loading a file) a...
0
1256
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 6, this control in .NET do not apply the expected formatting when there are multiple selection of different font formats. For example, if I select a text that have portions in Bold and other portion
2
3709
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"; richTextBox1.Text = aStr;
3
7192
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 just add plain (e.g.. rtf.Text += "new stuff..."; ) but some text, when added, I want to be in a different color or font size. Find() will not work because the text will vary. I have delimiters on it so I could recognize it with a regular ...
2
2589
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 and the added text is shown in another color. I scroll to the end and want to add the next status line using appendtext. But now the previous line lost its formatting...... I want to keep the formatting… Do you have a solution? BTW I am using...
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.