如何在状态栏上的文本框中显示行的位置? [英] How can I display the line position in a TextBox on the status bar?
本文介绍了如何在状态栏上的文本框中显示行的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我添加了一个StatusStrip
控件,并在其中放置了StatusLabel
.但是,现在我想知道如何将其连接到我的文本框以显示光标的行号和位置,例如:第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".
谢谢
推荐答案
-
在文本框中获取插入符号的索引:
Get the index of the caret in the TextBox:
C#
int caretIndex = textBox.SelectionStart;
VB.NET
Dim caretIndex As Integer = textBox.SelectionStart
从插入号索引中获取行号:
Get the line number from the caret index:
C#
int lineNumber = textBox.GetLineFromCharIndex(caretIndex);
VB.NET
Dim lineNumber As Integer = textBox.GetLineFromCharIndex(caretIndex)
获取当前行中的字符索引:
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 ...
这篇关于如何在状态栏上的文本框中显示行的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文