UWP Windows 10。
如何获取RichEditBox的行数?
我想将行计数,当前行和当前行绑定到状态栏中的标签(如在记事本中)。我怎么能这样做?
答案 0 :(得分:1)
看看这个扩展类
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; }
}