如何获取 RichTextBox 控件中的当前行?
假设我单击了 RichTextBox 控件内的某处。如何获取插入符当前所在的行?
顺便说一句,这是检索该行的整个文本字符串。
Say I clicked somewhere inside a RichTextBox control. How can I get the current line the caret is currently on?
Btw this is to retrieve the whole text string of that line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这对我有用:
This worked for me:
这就是 RichTextBox.GetLineFromCharIndex()做。传递 SelectionStart 属性值。
That's what RichTextBox.GetLineFromCharIndex() does. Pass the SelectionStart property value.
我的答案甚至比文森特的更棒,因为在获得正确的行号后,我注意到它在闪烁,非常可怕。因此,我添加了一个内存中的富文本框来在那里完成工作。
My answer is even more awesome than Vincent's because after getting the right line number I noticed it was flickering, horribly. So I added an in memory rich text box to do the work there.
一种方法是向其发送 EM_LINEFROMCHAR 消息。我确信还有其他方法。
One way is to send it the EM_LINEFROMCHAR Message. I'm sure there are other ways.
这是通过从文档的开头开始计数来实现的。
这是实际的功能。
This works by counting from the beginning of the document.
Here is the actual function.
如果您想从现在正在调试的编辑器控件中获取当前行号,那么
我认为这对您的问题很有帮助。
If you want to get current Line Number from the editor Control where you are debugging now then
I think it is helpful for your problem.