0

UWP Windows 10.

How to get lines count of RichEditBox?

I want to bind lines count, current line and current row to labels in statusbar (like in notepad). How can I do this?

SYL
  • 337
  • 4
  • 16
  • 2
    This question is duplicate http://stackoverflow.com/questions/34412421/richtextblock-text-line-count – soydachi Feb 14 '16 at 22:55
  • 1
    No, it's not. SYL asked for a richEDITbox support, not the richTEXTbox and they're pretty different. I'm also searching a way to display line numbers on the left side of my richEDITbox but my solutions are simply bad. – Martinocom Jul 22 '17 at 23:23

1 Answers1

0

Take a look at this extended class

public class TextBoxEx : TextBox
{
    public TextBoxEx()
    { }

    public void GoTo(int line, int column)
    {
        if (line < 1 || column < 1 || this.Lines.Length < line)
            return;

        this.SelectionStart = this.GetFirstCharIndexFromLine(line - 1) + column - 1;
        this.SelectionLength = 0;
    }

    public int CurrentColumn
    {
        get { return this.SelectionStart - this.GetFirstCharIndexOfCurrentLine() + 1; }
    }

    public int CurrentLine
    {
        get { return this.GetLineFromCharIndex(this.SelectionStart) + 1; }
    }
}

Or even better; you could just write it like this:

public int CurrentColumn
{
get { return textBox1.SelectionStart - textBox1.GetFirstCharIndexOfCurrentLine() + 1; }
}
Tobias Kullblikk
  • 226
  • 1
  • 12