Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Rich Text parsing with RichTextBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LarryF@drmworld.com - 18 Aug 2005 23:57 GMT
Hello,

I have some rich text strings saved in a database that I need to
convert to another format. I need to extract information like font and
color from the RTF strings. So I thought that I would just get a
RichTextBox and use it to interpret the RTF text for me, but the
RichTextBox doesn't seem to be able to understand my RTF. For example,
it tells me the color is always Color.Empty and the font is null, even
if I set them myself. The RTF text was originally created with VB6.0's
rich text control.

The documentation says that if the color changes in a selection, then
SelectionColor() returns Color.Empty. But it returns Color.Empty even
if I select a single character. How can a single character have a color
change? Then I set all the text to green just as a test, but
SelectionColor still returns Color.Empty.

Here's some C# code that shows the strange behavior:
string rtf =
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0
MS Sans Serif;}}\r\n{\\*\\generator Riched20
5.50.99.2009;}\\viewkind4\\uc1\\pard\\f0\\fs24 Here is some sample rich
text.\\par\r\n}\r\n\0"

RichTextBox rtb = new RichTextBox();
rtb.Rtf = rtf;
rtb.Select(0, 1);  // Select the first character.
if (rtb.SelectionColor == Color.Empty) {
  // How can a single character have a color change?
  rtb.Select(0, rtb.Text.Length - 1); // Select everything.
  rtb.SelectionColor = Color.Green;   // Make everything green.
  Console.WriteLine("Color: " + rtb.SelectionColor.ToString());
}

The code always writes "Color: Color [Empty]". The behavior is similar
when I work with SelectionFont.

I may be using the RichTextBox wrong, or the RTF strings may have a bad
format, or the RichTextBox may not operate correctly until it is placed
on a form. Can anyone tell me why the RichTextBox doesn't seem to work
with my rich text? Or is there some other tool I can use to parse rich
text?

Thanks for your help.
Lloyd Dupont - 19 Aug 2005 08:49 GMT
here you go:
http://www.codeproject.com/useritems/nrtftree.asp

Signature

If you're in a war, instead of throwing a hand grenade at the enemy, throw
one of those small pumpkins. Maybe it'll make everyone think how stupid war
is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.

> Hello,
>
[quoted text clipped - 40 lines]
>
> Thanks for your help.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.