1

我添加了一个StatusStrip控件并在其中放置了一个StatusLabel。但现在我想知道如何将它连接到我的 TextBox 以显示光标的行号和位置,例如:“第 2 行,第 6 行”。

谢谢

4

1 回答 1

3
  1. 获取文本框中插入符号的索引:

    C#

    int caretIndex = textBox.SelectionStart;
    

    VB.NET

    Dim caretIndex As Integer = textBox.SelectionStart
    
  2. 从插入符号索引中获取行号:

    C#

    int lineNumber = textBox.GetLineFromCharIndex(caretIndex);
    

    VB.NET

    Dim lineNumber As Integer = textBox.GetLineFromCharIndex(caretIndex)
    
  3. 获取当前行的字符索引:

    C#

    Point characterXY = textBox.GetPositionFromCharIndex(caretIndex);
    int characterIndex = textBox.GetCharIndexFromPosition(characterXY);
    

    VB.NET

    Dim characterXY As Point = textBox.GetPositionFromCharIndex(caretIndex)
    Dim characterIndex As Integer = textBox.GetCharIndexFromPosition(characterXY)
    

我想你可以从这里继续......

于 2011-04-17T09:56:10.393 回答