How to get the current row in a RichTextBox control?

Let's say I clicked somewhere inside the RichTextBox control. How can I get the current line the carriage is in?

Btw is for extracting the entire text string of this string.

+4
source share
4 answers

What does RichTextBox.GetLineFromCharIndex () do . Pass the value of the SelectionStart property.

+11
source

This worked for me:

this.WordWrap = false; int cursorPosition = this.SelectionStart; int lineIndex = this.GetLineFromCharIndex(cursorPosition); string lineText = this.Lines[lineIndex]; this.WordWrap = true; 
+11
source

One way is to send an EM_LINEFROMCHAR message . I am sure there are other ways.

+1
source

If you want to get the current line number from the Control editor, where you are currently debugging,

 int lineNumber = (new StackTrace()).GetFrame(1).GetFileLineNumber(); 

I think this is useful for your problem.

+1
source

Source: https://habr.com/ru/post/1307725/


All Articles