110,561
社区成员
发帖
与我相关
我的任务
分享
richTextBox1.SelectAll();
richTextBox1.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Underline);
System.Drawing.FontStyle style = richTextBox1.DrawingFontStyle();
MessageBox.Show(style.ToString()); // <-- result: Underline
string rtf = richTextBox1.RTF();
richTextBox1.LoadFromRTF(rtf);
richTextBox1.SelectAll();
style = richTextBox1.DrawingFontStyle();
MessageBox.Show(style.ToString()); // <-- result: Regular
public static string RTF(this RichTextBox richTextBox)
{
string rtf = string.Empty;
TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
using (MemoryStream ms = new MemoryStream())
{
textRange.Save(ms, System.Windows.DataFormats.Rtf);
ms.Seek(0, SeekOrigin.Begin);
StreamReader sr = new StreamReader(ms);
rtf = sr.ReadToEnd();
}
return rtf;
}