473,385 Members | 1,548 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,385 software developers and data experts.

Problems with RichTextBox.Rtf

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{\fontt bl{\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
May 31 '06 #1
2 9459
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.

"Flack" wrote:
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{\fontt bl{\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

Jun 1 '06 #2
Flack wrote:
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
Jun 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: nouno | last post by:
I am trying to spell check a richtextbox. Through code (shown below) I save the contents of the richtextbox to a rtf file, open the rtf file in Word, spell check it, save it, and then load the ftf...
2
by: JonnyT | last post by:
I searched high and low for an answer on how to auto scroll a richtextbox and now I finally have it. Since it took me a while to get a good efficient way of doing it that didn't require focus to...
0
by: Vincent | last post by:
Dear all, I have implemented a class to export the content of RichTextBox to image in WYSISYG mode so that line breaks on the screen are the same as exported. C# Code: public struct...
9
by: James Wong | last post by:
Hi, I use the RichTextBox in my program. It will use different language in this RichTextBox (chinese and english characters), and it set the "DualFont" and use different fonts. By the way, how...
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...
0
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep...
1
by: mootroot | last post by:
Hi all, im writing a program in C#, but i'm having a couple of problems with a richtextbox i have on my form. Firstly, I want a user to be able highlight a certain part of a line, but at the moment...
2
by: eBob.com | last post by:
I've been working on an app which has an array of RichTextBoxes. And I have a context menu for the RTBs. The context menu has two levels; the first level has two items, "Load Sample Text File"...
10
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i have text like this: "ACPI\GENUINEINTEL_-_X86_FAMILY_6_MODEL_13\_0" an after displaying it in a RichTextBox as RTF string, i get this: "ACPI_-_x86_Family_6_Model_13 "
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.