在RichTextBox的特定内容 [英] Particular content in richtextbox

查看:180
本文介绍了在RichTextBox的特定内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示一些大胆的形式一些简单的内容,所以我使用richtextbox.And我已经做了一个文件扩展名.rtf.Now我加载与使用的LoadFile的RichTextBox的该文件()函数。这个工作。但我想显示在RichTextBox的文件的特定内容,比如可能是第一个五线,也可能是线没。六ten.Then是有什么解决办法?

I want to display some bold and some simple content in the form so I am using richtextbox.And I have made one file with extension of .rtf.Now I load that file in the richtextbox with use of the Loadfile() function.This works. But I want to display particular content of the file in the richtextbox,like may be first five lines or it may be line no. of six to ten.Then is there any solution ??

推荐答案

这是可能的,只是不是很干净。这code使用其他RTB加载该文件,剪贴板,以获得格式化的RTF。要注意的是它破坏了剪贴板中的内容。

It is possible, just not very cleanly. This code uses another RTB to load the file and the clipboard to get the formatted RTF. Beware that it destroys the clipboard content.

  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();

这篇关于在RichTextBox的特定内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆