【问题标题】:XAML RichEditBox lines countXAML RichEditBox 行数
【发布时间】:2016-02-16 03:01:56
【问题描述】:

UWP Windows 10。

如何获取 RichEditBox 的行数?

我想将行数、当前行和当前行绑定到状态栏中的标签(如记事本中)。我该怎么做?

【问题讨论】:

  • 不,不是。 SYL 要求提供richEDITbox 支持,而不是richTEXTbox,它们完全不同。我还在寻找一种在我的richEDITbox 左侧显示行号的方法,但我的解决方案很糟糕。

标签: c# xaml windows-10 win-universal-app windows-10-universal


【解决方案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; }
}

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 2022-01-01
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多