C#RichTextBox复制并跳转指定行

方法一:

                rTxt.Focus();
                //设置文本框中选定的文本起始点 为 指定行数第一个字符的索引
                rTxt.SelectionStart = rTxt.GetFirstCharIndexFromLine(nowLineIndex);
                //设置控件中选定的字符数
                rTxt.SelectionLength = rTxt.Lines[nowLineIndex].Length;

方法二:

                rTxt.Focus();
                //选择文本框中的文本范围
                rTxt.Select(rTxt.GetFirstCharIndexFromLine(nowLineIndex), rTxt.Lines[nowLineIndex].Length);

 主要是用到GetFirstCharIndexFromLine方法,获取指定行数第一个字符的索引,不用自己去循环判断了

注意:要先设置RichTextBox选中,才能操作某些属性

原文地址:https://www.cnblogs.com/leiyongbo/p/10722536.html