如何在RichTextBox控件中获取当前行?

Joa*_*nge 3 .net c# richtextbox winforms

假设我点击了RichTextBox控件中的某个位置.如何获得当前插入符号的当前行?

顺便说一下,这是检索该行的整个文本字符串.

小智 12

这对我有用:

this.WordWrap = false;
int cursorPosition = this.SelectionStart;
int lineIndex = this.GetLineFromCharIndex(cursorPosition);
string lineText = this.Lines[lineIndex];
this.WordWrap = true;
Run Code Online (Sandbox Code Playgroud)


Han*_*ant 11

这就是RichTextBox.GetLineFromCharIndex()的作用.传递SelectionStart属性值.