UWP Windows 10。
如何获取RichEditBox的行数?
我想要将行数、当前行和当前行绑定到statusbar中的标签(如记事本中)。我该怎么做呢?
发布于 2016-02-15 03:58:38
看一下这个扩展的类
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; }
}
}或者更好;您可以像这样编写它:
public int CurrentColumn
{
get { return textBox1.SelectionStart - textBox1.GetFirstCharIndexOfCurrentLine() + 1; }
}https://stackoverflow.com/questions/35392496
复制相似问题