This is a migrated thread and some comments may be shown as answers.

How to get position from char index in RadRichTextEditor

6 Answers 245 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Aakash Kumar
Top achievements
Rank 1
Aakash Kumar asked on 12 Jan 2017, 04:58 PM

as RichTextBox has a method like:

Point p = richTextBox1.GetPositionFromCharIndex(3);

 

What is the method for that in RadRichTextEditor?

I want to get position of particular index in RadRichTextEditor.

Thanks in advance

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Jan 2017, 08:49 AM
Hello Aakash Kumar,

Thank you for writing.  

RadRichTextEditor has a specific positioning feature to navigate through document's content and to get information about the document's elements at a specific position. RadDocument uses the positioning to track the movement of the and to control the selection. You can navigate to a specific position in the document and get the DocumentPosition.Location property. Additional information about positioning is available here: http://docs.telerik.com/devtools/winforms/richtexteditor/features/positioning

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Aakash Kumar
Top achievements
Rank 1
answered on 13 Jan 2017, 11:40 AM

Thanks to Respond Dess.

Actually i need the location of char by index. Like the location of  5th char of radRichTextBox in X and Y axis.

Can you please help me?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 13 Jan 2017, 11:56 AM
Hello Aakash Kumar, 

Thank you for writing back. 

RadRichTextEditor doesn't provide such an API to get the position by char index directly. The possible solution is to use the DocumentPosition which should be placed at the beginning of the document and move it to the next character by the MoveToNext method. Thus, you can access the desired char's location by index. Here is a sample code snippet:
this.radRichTextEditor1.Text = "Once upon a time";
Telerik.WinForms.Documents.DocumentPosition position = new Telerik.WinForms.Documents.DocumentPosition(this.radRichTextEditor1.Document);
int index = 6;
while (index > -1)
{
    position.MoveToNext();
    index--;
}
Console.WriteLine(position.Location.ToString());

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Aakash
Top achievements
Rank 1
answered on 13 Jan 2017, 04:31 PM
Thanks dear, thank you very much. 
0
sebastien
Top achievements
Rank 1
answered on 22 Nov 2018, 05:02 PM

Is it possible to get the same function with a RadTextBox ?

Since I'm using a RadExpressionEditorForm, I can't change the type of the [radTextBoxExpression]...

thanks

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Nov 2018, 07:51 AM
Hello, Sebastien, 

Note that RadRichTextEditor and RadTextBox have a completely different internal elements structure. Hence, the API is different. RadTextBox also hosts the standard MS TextBox. You can refer to the following general programming forums demonstrating how to get the char value form a position (index). You can get the hosted TextBox by the RadTextBox.TextBoxElement.TextBoxItem.TextBoxControl:
https://stackoverflow.com/questions/5564319/getting-char-from-position-in-c-sharp-textbox
https://social.msdn.microsoft.com/Forums/en-US/c5290a83-c2eb-4b4d-9590-ae76b1e6fb32/textbox-how-to-get-char-position-if-i-know-line-number?forum=csharpgeneral&forum=csharpgeneral

I hope this information helps. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextEditor
Asked by
Aakash Kumar
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Aakash Kumar
Top achievements
Rank 1
Aakash
Top achievements
Rank 1
sebastien
Top achievements
Rank 1
Share this question
or