SOS:利用WPF RichTextBox 提取RTF, 莫名丢掉了Underline样式信息
主代码是这样写的:
1
richTextBox1.SelectAll();
2
richTextBox1.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Underline);
3
System.Drawing.FontStyle style = richTextBox1.DrawingFontStyle();
4
MessageBox.Show(style.ToString()); // <-- result: Underline
5![]()
6
string rtf = richTextBox1.RTF();
7
richTextBox1.LoadFromRTF(rtf);
8
richTextBox1.SelectAll();
9
style = richTextBox1.DrawingFontStyle();
10
MessageBox.Show(style.ToString()); // <-- result: Regular
11![]()
richTextBox1.SelectAll();2
richTextBox1.Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Underline);3
System.Drawing.FontStyle style = richTextBox1.DrawingFontStyle();4
MessageBox.Show(style.ToString()); // <-- result: Underline5

6
string rtf = richTextBox1.RTF();7
richTextBox1.LoadFromRTF(rtf);8
richTextBox1.SelectAll();9
style = richTextBox1.DrawingFontStyle();10
MessageBox.Show(style.ToString()); // <-- result: Regular 11

运行的结果:
第一次显示: Underline
第二次显示: Regular
而RichTextBox里的字体始终是带有下划线的。个人分析的结果为 RichTextBox 提取RTF的字符串丢掉了Underline样式, 那么改如何修正呢?
提取RTF字符串:
读取RTF:
解析FontStyle:
完整的Source:/Files/anders06/RTFConvertor.zip





}
}
浙公网安备 33010602011771号