[C#.NET][Infopath 2007] Rich Text Box(RTF 文字方塊) 換行
InfoPath中的Rich Text Box是XHtml的格式,所以用\r\n或是用System.Environment.NewLine,都不會換行。
使用下列程式碼即可。
public void CTRL27_5_Clicked(object sender, ClickedEventArgs e)
{
// 在此處寫入您的程式碼。
XmlReader xr;
XPathNavigator root = MainDataSource.CreateNavigator();
XPathNavigator RichTextBox = root.SelectSingleNode("/my:myFields/my:ShowValue", NamespaceManager);
string id = "12";
string name = "余小章";
xr = XmlReader.Create(new StringReader("<div xmlns=\"http://www.w3.org/1999/xhtml\">" + id + "</div>"));
RichTextBox.AppendChild(xr);
xr = XmlReader.Create(new StringReader("<div xmlns=\"http://www.w3.org/1999/xhtml\"> "+name+" </div>"));
RichTextBox.AppendChild(xr);
}
或是使用
public void CTRL29_5_Clicked(object sender, ClickedEventArgs e)
{
string id = "12";
string name = "余小章";
string str = string.Empty;
XPathNavigator domNav = MainDataSource.CreateNavigator();
string xhtmlRTFField = domNav.SelectSingleNode("/my:myFields/my:ShowValue", NamespaceManager).InnerXml;
str += "<div xmlns=\"http://www.w3.org/1999/xhtml\">" + id + "</div>";
str += "<div xmlns=\"http://www.w3.org/1999/xhtml\">" + name + "</div>";
domNav.SelectSingleNode("/my:myFields/my:ShowValue", NamespaceManager).InnerXml = str;
}
以上方法都可以換行
若有謬誤,煩請告知,新手發帖請多包涵
Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET