Problems with RichTextBox.Rtf

G

Guest

Hey guys,

I'm trying to set the Rtf property of a Richtextbox and I'm having some
issues.

First I do this, which works fine:

string test =
@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0
Arial;}}
{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\ul\f0\fs20
Test\ulnone\par}";

this._agreementTextBox.Rtf = test;

The textbox displays the underlined word "Test".

However, when I try to do the same thing but instead read the rtf from a
CDATA section in an xml file, I get an exception thrown:

Here is the XML:
<Options>
<Item key="CLICK_THROUGH_TEXT"><![CDATA[
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0
Arial;}}
{\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\ul\f0\fs20
Test\ulnone\par
}
]]></Item>
</Options>

Code:
string xPath = String.Format("Item[@key='{0}']", Settings.CLICK_THROUGH_TEXT);
XmlNode node = agreementConfig.GetNode(xPath,null);
if (node != null)
{
this._agreementTextBox.Text = node.InnerText;
}

This throws an System.ArgumentException: Invalid file format.
at System.Windows.Forms.RichTextBox.StreamIn(Stream data, Int32 flags)

Can anyone tell me how I can read it from the xml and get it to work properly?

THanks,
-Flack
 
G

Guest

Arg. My mistake on the second one. The .Text is a typo, I actually do use the
correct Rtf property.

As for the string returned in InnerText, I looked at both the explicit
string I created, that I know works, and the InnerText string. In the
debugger, when I look at the strings, they are identical, however, in the
command window, while debugging I compared the two strings for equality and
it returned false. I don't know whats different about them.
 
D

Dan Manges

Flack said:
As for the string returned in InnerText, I looked at both the explicit
string I created, that I know works, and the InnerText string. In the
debugger, when I look at the strings, they are identical, however, in the
command window, while debugging I compared the two strings for equality and
it returned false. I don't know whats different about them.

You make want to add a .Trim() to the string from the XML. It may have
leading or trailing \r's or \n's which could cause problems.

Dan Manges
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top