I'm using the following snippet to find text
I'd like to know how to get the line number of the textRange found and the entire text of the line that contains textRange.
Tommaso
private
void
HightlightText(
string
textToHighlight)
{
DocumentTextSearch search =
new
DocumentTextSearch(
this
.radRichTextBox1.Document);
foreach
(var textRange
in
search.FindAll(textToHighlight))
{
this
.radRichTextBox1.Document.Selection.AddSelectionStart(textRange.StartPosition);
this
.radRichTextBox1.Document.Selection.AddSelectionEnd(textRange.EndPosition);
this
.radRichTextBox1.ChangeTextHighlightColor(Color.Red);
}
}
I'd like to know how to get the line number of the textRange found and the entire text of the line that contains textRange.
Tommaso
6 Answers, 1 is accepted
0
Hi Tommaso,
It is not possible to determine the line number in the whole document. You can get the line number in the context of paragraph only. This restriction is caused because RadRichTextBox supports complex and nested layouts which cannot produce the line number as well as a pure text editor. You can get the line index inside the paragraph by using the following code snippet:
I hope this helps.
Regards,
Svett
the Telerik team
It is not possible to determine the line number in the whole document. You can get the line number in the context of paragraph only. This restriction is caused because RadRichTextBox supports complex and nested layouts which cannot produce the line number as well as a pure text editor. You can get the line index inside the paragraph by using the following code snippet:
textRange.StartPosition.GetCurrentInlineBox().LineInfo.Paragraph
I hope this helps.
Regards,
Svett
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Tommaso
Top achievements
Rank 1
answered on 11 Oct 2012, 03:26 PM
What property or method of
I must use to get line index?
textRange.StartPosition.GetCurrentInlineBox().LineInfo.Paragraph
0
Hi Tommaso,
I posted the wrong code snippet. Please excuse me for the misunderstanding.
You can get the index in paragraph by using the following line:
Kind regards,
Svett
the Telerik team
I posted the wrong code snippet. Please excuse me for the misunderstanding.
You can get the index in paragraph by using the following line:
textRange.StartPosition.GetCurrentInlineBox().LineInfo.IndexInParagraph
Kind regards,
Svett
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Tommaso
Top achievements
Rank 1
answered on 16 Oct 2012, 03:00 PM
Unfortunately the value I got is always 0.
The document I attach to the RichTextBox is a plain text document.
0
Accepted
Hi Tommaso,
The IndexInParagraph property can return zero, if the paragraph contains only one line. You can calculate the line number of the word by using the following code snippet:
Note that the code above will work, if the document contains only paragraphs and text (excluding tables and images).
Regards,
Svett
the Telerik team
The IndexInParagraph property can return zero, if the paragraph contains only one line. You can calculate the line number of the word by using the following code snippet:
InlineLayoutBox box = textRange.StartPosition.GetCurrentInlineBox();
int
index = box.LineInfo.IndexInParagraph;
int
lineNumber = box.LineInfo.Paragraph.ChildIndex + index;
Note that the code above will work, if the document contains only paragraphs and text (excluding tables and images).
Regards,
Svett
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Tommaso
Top achievements
Rank 1
answered on 19 Oct 2012, 12:43 PM
The snippet works if I add 1 to the lineNumber value.
Thanks for your support.