How to get position from char index in RadRichTextEditor

7 posts, 0 answers
  1. Aakash Kumar
    Aakash Kumar avatar
    2 posts
    Member since:
    Jan 2017

    Posted 12 Jan 2017 Link to this post

    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

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3465 posts

    Posted 13 Jan 2017 Link to this post

    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 caret 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.
  3. Aakash Kumar
    Aakash Kumar avatar
    2 posts
    Member since:
    Jan 2017

    Posted 13 Jan 2017 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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?

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3465 posts

    Posted 13 Jan 2017 Link to this post

    Hello Aakash Kumar, 

    Thank you for writing back. 

    RadRichTextEditor doesn't provide such an API to get the X,Y 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.
  5. Aakash
    Aakash avatar
    3 posts
    Member since:
    Jun 2016

    Posted 13 Jan 2017 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks dear, thank you very much. 
  6. sebastien
    sebastien avatar
    42 posts
    Member since:
    May 2017

    Posted 22 Nov 2018 Link to this post

    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

     

  7. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3465 posts

    Posted 23 Nov 2018 Link to this post

    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.
Back to Top