zoukankan      html  css  js  c++  java
  • C# RichTextBox跳转到指定行(文本行跳转和显示行跳转)

    文本行跳转:

     对禁止自动换行(WordWrap属性为False)有效

    1 /// <summary>跳到指定行</summary>
    2 private void JumpToLine(int lineIndex)
    3 {
    4     rtxContext.SelectionStart = rtxContext.GetFirstCharIndexFromLine(lineIndex);
    5     rtxContext.SelectionLength = 0;
    6     rtxContext.Focus();
    7     rtxContext.ScrollToCaret();
    8 }

    显示行跳转:

     对自动换行(WordWrap属性为True)有效(由于是用Find(),对于内容存在多行文本相同并且靠的很近的情况,依然会出现跳转错误!

     1 /// <summary>跳到指定行</summary>
     2 private void JumpToLine(int lineIndex)
     3 {
     4     var charindex= rtxContext.GetFirstCharIndexFromLine(lineIndex);//不需要也可以,那么对应的Find()参数为0,我处理的是比较大的文章,so...
     5     var strline = rtxContext.Lines[lineIndex];
     6     var viewindex = rtxContext.Find(strline, charindex, RichTextBoxFinds.None);
     7     rtxContext.SelectionStart = viewindex;
     8     rtxContext.SelectionLength = 0;
     9     rtxContext.Focus();
    10     rtxContext.ScrollToCaret();
    11 }
  • 相关阅读:
    RaisedButton
    Icon
    RichText
    GridView
    HTML常用标签
    HTML语法
    HTML简史
    17_继承
    16_Math
    16_ArrayList
  • 原文地址:https://www.cnblogs.com/xiii/p/14257320.html
Copyright © 2011-2022 走看看