473,326 Members | 2,113 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,326 software developers and data experts.

formatting a string into a richtextbox

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 5455
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
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.text 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.selectionFont, 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
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...
2
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...
1
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: ...
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,...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.