【问题标题】:Select Range get line Text in wpf richtextbox在wpf Richtextbox中选择范围获取行文本
【发布时间】:2015-08-15 05:20:08
【问题描述】:

我正在实施逐步对齐。

获取 rtb1 中的当前行。 并在 rtb2 中显示。

我想要

第一行111111111111111

第二行222222222222222

第三行 3333333333333333

但是

第一行 1111111111111111 第二行 22222222222222

第三行 3333333333333333

第四行 4444444444444444

我不知道我的错误... 这..我的一些代码.. line 方法获取当前行, 所以,richTextLineIndex 是行的起始索引。

    private int GetTextPositionAndLength(int position, int lineIndex, out int length)
    {
        int richTextLineIndex = GetFirstCharIndexFromLine();

        TextPointer textpointer = rtb1.CaretPosition.DocumentStart;
        string line = Lines(count);

        if (position == 0)
        {
            length = GetTextLength(0, lineIndex);
            rtb2.AppendText(line);
            return richTextLineIndex;
        }
        rtb2.AppendText(line);

        return index + richTextLineIndex;
    }
    private string Lines(int LineIndex, string Default = "null")
    {
        TextPointer start= rtb1.CaretPosition.DocumentStart.GetPositionAtOffset(startPoint);
        TextPointer end = rtb1.CaretPosition;
        var range = new TextRange(start, end);
        line = range.Text;
        startPoint += line.Length;
        return line;
    }

【问题讨论】:

    标签: c# wpf richtextbox


    【解决方案1】:

    你试过了吗

      rtb2.AppendText(line+"\r");
    

    【讨论】:

      【解决方案2】:

      rtb2.Text = rtb2.Text + Environment.NewLine + line;

      【讨论】:

      • 请在您的回答中添加一些解释。
      猜你喜欢
      • 1970-01-01
      • 2010-11-30
      • 2014-11-02
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多