473,804 Members | 3,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

formatting a string into a richtextbox

3 New Member
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 string into the display with a single word bolded.

I appreciate the help. Thanks

~Chris
Apr 21 '06 #1
2 5493
Chris Rollock
3 New Member
I've tried using rtf tags encoded into the string via appendtext and it seems to add it to rtf the same as any other tags, but then it still doesn't display properly. EG the string "\\b This is test text. \\b0" gets added to rtf like "\\\\b This is test text. \\\\b0". Using \b and \b0 create odd graphical characters rather than being passed as an escape control.

Er, additionally/instead of a solution to this, perhaps someone could answer a more fundimental question of what the best way to display dynamically chosen text in an environment that allows copy/paste and can display different font sizes, colors, and styles in the same window? I assumed this was the proper way to do it, given an example of a program that was written in java that I'm trying to emulate (I don't have the code for it). The text box used there behaves exactly like the richtextbox control that I'm using. Except of course for the working/not working part.
Apr 21 '06 #2
Chris Rollock
3 New Member
Sorry if this bump/post goes against board manners. I'm still trying to get a solution to what seems like it should be an extremely simple problem. Here's further updates on what I tried and what I'm looking for...

What the richtextbox actually looks at when it reads text is richtextbox.rtf . Any attempt to pass text into it via append text or directly throuh richtextbox.tex t passes control characters as \\ so that when they are displayed, they come out as a \. It also won't let me pass a single \ through either method as it looks to convert the control before it ever hits .rtf.

This leads me to believe there are two solutions to my problem. The first is to give the text directly to .rtf. This would be fine except that .rtf has multiple sections and text has to be put in a very specific part. I can't just append to the end. That means I have to include an algorithm to find and insert my string into the middle of the .rtf. My other option is to use rtb.selectionFo nt, which doesn't work for me because the control characters are inserted into the string as I read from the XML file. I'm using a hashtable to store everything, and I don't want to keep track of what needs to be bold/italic/red etc. after I read it that first time. It loses its context at that point and becomes more difficult to accurately manipulate.

I can't help but feel both of these solutions are overly complex for how simple a process this is. Unless someone has a better solution, I'll go ahead with the first method of searching through the rtf string.
Apr 21 '06 #3

Sign in to post your reply or Sign up for a free account.

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>
2
17290
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>
1
2576
by: Grant | last post by:
Hi, While iterating through a loop and building a string is it possible to format certain string value? the completed string eventually gets passed to a rich TextBox. for example: ------------------ string thing = "";
1
7945
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.
0
1258
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
3711
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
9706
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
9577
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
10569
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
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
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...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2990
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.