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

DocumentPosition.SetPosition(PointF )is not working properly

1 Answer 59 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Neelima
Top achievements
Rank 1
Neelima asked on 10 Nov 2014, 04:07 PM
I am trying to capture the mouse location(hover) and trying to display a tooltip based on the text that is highlited.
For that i am doing this

          var p = e.GetPosition(null);            
           DocumentPosition position = new DocumentPosition(this.ArcEditor.Document);           
           position.SetPosition(p.ToPointF());
          var pBox = position.GetCurrentInlineBox(); 

But my position is always pointing to the same location. My mouse coordinates(p) are changing with the mouse move but documnet position is not set properly.

Can someone help me on this.

Thanks in advance.

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 12 Nov 2014, 12:35 PM
Hello Neelima,

Basing on the provided code, you can attach to the RadRichTextBox's MouseMove event and the handler should looks like as follows:
private void RadRichTextBox_MouseMove(object sender, MouseEventArgs e)
{
    RadRichTextBox richTextBox = (RadRichTextBox)sender;
 
    Point point = e.GetPosition(richTextBox);
    point.X /= richTextBox.ScaleFactor.Width;
    point.Y /= richTextBox.ScaleFactor.Height;
 
    DocumentPosition position = new DocumentPosition(richTextBox.Document);
    position.SetPosition(point.ToPointF());
    
    var inlineLayoutBox = position.GetCurrentInlineBox();
    // ...
}


Please, note that the provided code above will work when RadRichTextBox is in Flow or FlowNoWrap LayoutMode. For Paged mode, you should implement different logic. 

I'm not sure what is your final goal you should achieve, but instead of showing a tooltip, you can implement your own custom UI layer and visualize the necessary information there.
You can check our Customize Presentation demo or this SDK demo on that matter. You can read more about custom UI layers in this help article.

I hope this helps.

Regards,
Todor
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
RichTextBox
Asked by
Neelima
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or