RichTextBox.Rtf property argument exception
-
Hey all, I'm trying to programmatically fill RichTextBox's Rtf property, I have an Xml file thats built like CP breaks the XML, so here's a tree representation:
Paragraphs
Paragraph
Header
ContentI then iterate through all paragraphs and if the header isn't empty, i add it like so: string rtbContent += "\b" + headerNode.InnerText + "\b0"; but when I set the RichTextBox's Rtf Property to rtbContent, it throws an ArgumentException stating the string is in the wrong format... Why, the Rtf property is a string, and so is my variable...
-
Hey all, I'm trying to programmatically fill RichTextBox's Rtf property, I have an Xml file thats built like CP breaks the XML, so here's a tree representation:
Paragraphs
Paragraph
Header
ContentI then iterate through all paragraphs and if the header isn't empty, i add it like so: string rtbContent += "\b" + headerNode.InnerText + "\b0"; but when I set the RichTextBox's Rtf Property to rtbContent, it throws an ArgumentException stating the string is in the wrong format... Why, the Rtf property is a string, and so is my variable...
You probably do not have the entire text wrapped with RTF formatting strings. For example, below is just a string of text typed into wordpad then viewed in Notepad.
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20 This is RTF text\par
} -
Hey all, I'm trying to programmatically fill RichTextBox's Rtf property, I have an Xml file thats built like CP breaks the XML, so here's a tree representation:
Paragraphs
Paragraph
Header
ContentI then iterate through all paragraphs and if the header isn't empty, i add it like so: string rtbContent += "\b" + headerNode.InnerText + "\b0"; but when I set the RichTextBox's Rtf Property to rtbContent, it throws an ArgumentException stating the string is in the wrong format... Why, the Rtf property is a string, and so is my variable...
When assigning the
Rtf
property, you must include all necessary RTF information, including the RTF headers. See the RTF 1.6 Specification[^] on MSDN for more information.Microsoft MVP, Visual C# My Articles