简体   繁体   中英

Select Range get line Text in wpf richtextbox

I'm implementing a step-by-step alignment.

Getting current line in rtb1. and to show in rtb2.

i want

first line 111111111111111

second line 222222222222222

thrid line 3333333333333333

but

first line 1111111111111111 second line 22222222222222

thrid line 3333333333333333

fouth line 4444444444444444

i don't know my error... this.. some of my code.. line method get current line, so, richTextLineIndex is line's start Index.

    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;
    }

你有没有尝试过

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM