大家好,我将日志文件写入一个有下划线、加粗等格式的.rtf文件中。我已经保存了这个文件,并希望在以后的时间将它读回到RichTextBox
中,保持其格式。我尝试了以下方法:
tmpRichTextBox.LoadFile(@"F:\Path\File.rtf", RichTextBoxStreamType.RichText);
它加载了文件,但没有我的原始格式。如果我将.rtf加载到Word中,格式将显示出来。如何将.rtf读回
RichTextBox
,包括其格式?谢谢您的时间。大家好,我将日志文件写入一个有下划线、加粗等格式的.rtf文件中。我已经保存了这个文件,并希望在以后的时间将它读回到RichTextBox
中,保持其格式。我尝试了以下方法:
tmpRichTextBox.LoadFile(@"F:\Path\File.rtf", RichTextBoxStreamType.RichText);
RichTextBox
,包括其格式?谢谢您的时间。 private void button1_Click(object sender, EventArgs e)
{
string fileName = Path.Combine(Environment.CurrentDirectory, "log1.htm");
webBrowser1.DocumentText = File.ReadAllText(fileName);
}
编辑:
有可能你在编程中会丢失格式。某些操作可能会导致格式丢失,例如:
richTextBox.Font = newFont;
我曾经遇到过这个问题,但幸运的是我找到了一个解决方法。下面是代码,可以让你在不丢失格式的情况下更改字体:
richTextBox.SelectAll();
richTextBox.SelectionFont = newFont;
string rtf = richTextBox.SelectedRtf;
richTextBox.Font = newFont;
richTextBox.Rtf = rtf;
RichTextBox
中,格式将会消失。感谢您的时间。 - MoonKnight