我想在表单中显示一些粗体和一些简单的内容,所以我使用了richtextbox。并且我制作了一个扩展名为.rtf的文件。现在我使用Loadfile()函数将该文件加载到richtextbox中.这有效。但我想在 Richtextbox 中显示文件的特定内容,例如可能是前五行,也可能是第 1 行。六到十。那么有什么解决办法吗?
最佳答案
这是可能的,只是不太干净。此代码使用另一个 RTB 加载文件和剪贴板以获取格式化的 RTF。请注意,它会破坏剪贴板内容。
using (var helper = new RichTextBox()) {
helper.LoadFile(@"c:\temp\test.rtf");
// Copy line #6
int startRange = helper.GetFirstCharIndexFromLine(5);
int endRange = helper.GetFirstCharIndexFromLine(6);
helper.SelectionStart = startRange;
helper.SelectionLength = endRange - startRange;
helper.Copy();
}
richTextBox1.SelectAll();
richTextBox1.Paste();
关于c# - RichTextBox 中的特定内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1990937/