Following is code that demonstrates the only way I could programmatically
set a rich text field and retain the formatting. It is written in C#, for
IP2003. It uses the clipboard ala IPC.
Call the method like so:
insertRichText(@"<h1>foo</h1>", "//aRichTextField");
And here
is the method:
public void insertRichText(string
richText, string xPathForInsertion)
{
//Declarations
StringBuilder
sb;
IXMLDOMNode
xNodeTarget;
Encoding
encoding;
string
htmlPrefix;
string
htmlSuffix;
//Assignments
xNodeTarget =
thisXDocument.DOM.documentElement.selectSingleNode(xPathForInsertion);
sb = new
StringBuilder();
encoding = Encoding.UTF8;
htmlPrefix = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD
HTML 4.0 Transitional//EN""><html><head><meta
http-equiv=Content-Type content=""text/html;
charset={0}""></head><body><!--StartFragment-->";
htmlSuffix = @"<!--EndFragment--></body></html>";
htmlPrefix = string.Format(htmlPrefix, encoding.WebName);
htmlSuffix = string.Format(htmlSuffix, encoding.WebName);
//Add the
top to the clip
sb.Append(htmlPrefix);
//Add the
content to the clip
sb.Append(richText);
//Add the
bottom to the clip
sb.Append(htmlSuffix);
//Add the
clip to the clipboard
System.Windows.Forms.DataObject clipDO = new
System.Windows.Forms.DataObject();
clipDO.SetData(System.Windows.Forms.DataFormats.Html,
sb.ToString());
System.Windows.Forms.Clipboard.SetDataObject(clipDO, true);
//Select
field element
thisXDocument.View.SelectText(xNodeTarget, Type.Missing);
//Paste
into element
thisXDocument.View.ExecuteAction("Paste", Type.Missing);
}