Re: Rich Text parsing with RichTextBox

Tech-Archive recommends: Fix windows errors by optimizing your registry



here you go:
http://www.codeproject.com/useritems/nrtftree.asp

--
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.
<LarryF@xxxxxxxxxxxx> wrote in message
news:1124405834.236427.313080@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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.
>


.



Relevant Pages

  • RE: Effective coloring in RichTextBox
    ... Making RTF code by hand appeared on my mind, but that's what I didnt want to ... This control is a superset of the RichTextBox control. ... RichTextBox control with the ability to capture, recognize, and display ink. ... manually and avoid the calling of SelectionColor ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Rich Text parsing with RichTextBox
    ... I have some rich text strings saved in a database that I need to ... RichTextBox and use it to interpret the RTF text for me, ... RichTextBox doesn't seem to be able to understand my RTF. ...
    (microsoft.public.dotnet.framework)
  • RE: Effective coloring in RichTextBox
    ... manually and avoid the calling of SelectionColor ... I don't think there is a way to get good performance with the RichTextBox ... in reconstituting the RichTextBox's .rtf field which is a very large string ... To get good performance with a RichTextBox, you could build the rtb's .rtf ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: C Sharp RichEditBox HyperLinks
    ... create files that that have the extension rtf. ... will load a rtf into my RichTextBox. ... Now using word I can take any letters or string of letters and ...
    (comp.programming)
  • RE: Initializing a RichTextBox
    ... The Rtf property of RichTextBox gets or sets the text of the RichTextBox ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.windowsforms)