如何在状态栏上的文本框中显示行位置?

发布于 2024-11-02 01:31:46 字数 142 浏览 1 评论 0原文

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

谢谢

I have added a StatusStrip control and placed a StatusLabel inside of it. But now I want to know how to connect it to my TextBox to show the line number and position of the cursor, like: "Line 2, Row 6".

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚殇 2024-11-09 01:31:46
  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#

    点字符XY = textBox.GetPositionFromCharIndex(caretIndex);
    int characterIndex = textBox.GetCharIndexFromPosition(characterXY);
    

    VB.NET

    暗淡字符XY As Point = textBox.GetPositionFromCharIndex(caretIndex)
    Dim characterIndex As Integer = textBox.GetCharIndexFromPosition(characterXY)
    

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

  1. Get the index of the caret in the TextBox:

    C#

    int caretIndex = textBox.SelectionStart;
    

    VB.NET

    Dim caretIndex As Integer = textBox.SelectionStart
    
  2. Get the line number from the caret index:

    C#

    int lineNumber = textBox.GetLineFromCharIndex(caretIndex);
    

    VB.NET

    Dim lineNumber As Integer = textBox.GetLineFromCharIndex(caretIndex)
    
  3. Get the character index in the current line:

    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)
    

I guess you can continue from here ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文