首页 文章

在richtextbox中附加到多个RTF文件

提问于
浏览
1

我有列表字符串和相应的RTF字符串,那么如何使用迭代在 RichTextBox 中追加?

this.PreviewRichText.Text = string.Empty;
for (int x = 0; x < entriesList.Count; x++) 
{
    this.PreviewRichText.AppendText(entriesList[x].Excerpt); 
    this.PreviewRichText.Rtf = entriesList[x].ExcerptRtf; 
    _summarycomment += entriesList[x].ReReviewComment ; 
}

1 回答

  • 0

    假设 rtfContents 是您的rtf文件内容的字符串列表,您可以使用以下代码:

    List<string> rtfContents = new List<string>(); //Load it from somewhere 
    richTextBox1.Text = string.Empty;
    foreach (string rtf in rtfContents)
    {
        richTextBox1.Select(richTextBox1.TextLength, 0);
        richTextBox1.SelectedRtf = rtf;
    }
    

    关键是,在每轮循环中,将选择移动到 RichTextBox 的末尾,然后将 SelectedRtf 设置为要追加的内容 .

    您可以创建这样的方法:

    public void AppendRtf(RichtextBox rtb, string rtf)
    {
        rtb.Select(rtb.TextLength, 0);
        rtb.SelectedRtf = rtf;
    }
    

相关问题