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

How to show a popup under a hyperlink in richtextbox with exact position?

1 Answer 31 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
kun
Top achievements
Rank 1
kun asked on 14 Jan 2016, 01:46 PM

Holle

 We used a listbox as a popup to show drop-down box under the hyperlinks in Radrichtextbox, but we can not locate the position of the listbox (drop-down box). We located the position at the Caret now, but this did not meet our requirement. We plan to locate the position at the start of a hyperlink, could you please help us.

What we should explain is that: the language we used is Chinese, far from English words, there is no space between Chinese words in a sentence, 

the English sentences: Telerick is a very good company.

but in Chinese, the sentence is: Telerick是一个非常好的公司

We located the position of caret, and calculated the length between the start and the end of hyperlink, and put the listbox at the position :caret-the length. But the listbox always display in a wrong position..

Thanks a lot, we hope your answer.

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 19 Jan 2016, 09:49 AM
Hello Wang,

Setting the associated to the Hyperlink's annotation markers LayoutBox's bounding rectangle as a Popup's PlacementRectangle should do the job in your case. However, if RadRichTextBox is not in its default Flow layout mode, but in Paged layout mode instead, you should modify that bounding rectangle a bit in order the "gaps" between the Document and ScrollBars to be taken into account. 

For example, you could use the following code snippet when the Popup should be opened in order to show it under the hyperlink:
HyperlinkRangeStart hyperlink = this.radRichTextBox.Document.EnumerateChildrenOfType<HyperlinkRangeStart>().LastOrDefault();
if (hyperlink != null)
{
    LayoutBox hyperlinkLayoutBox = hyperlink.GetAssociatedLayoutBoxes().FirstOrDefault();
 
    Popup popup = new Popup();
    popup.PlacementTarget = this.radRichTextBox;
    popup.Width = 200;
    popup.Height = 200;
    //popup.Child = Set the Popup's content child...
 
    Rect placementRectangle = hyperlinkLayoutBox.ControlBoundingRectangle.ToRect();
    if (this.radRichTextBox.LayoutMode == DocumentLayoutMode.Paged)
    {
        double y = placementRectangle.Y - this.radRichTextBox.VerticalOffset + placementRectangle.Height;
        double x = placementRectangle.X + (this.radRichTextBox.ActualWidth - this.radRichTextBox.Document.DocumentLayoutBox.BoundingRectangle.Width) / 2;
    
        placementRectangle = new Rect(x, y, placementRectangle.Width, placementRectangle.Height);
    }
 
    popup.PlacementRectangle = placementRectangle;
    popup.IsOpen = true;
}

Please note, it might be necessary to change the "x" and "y" calculations depending on your scenario.

I hope this helps.

However, if you have other questions or any further problems with the implementation of the above-mentioned rectangle's calculations, please try to isolate the issue in a sample project and send it to us. In this way, it will be much easier for us to help you to achieve the desired goal.

Regards,
Todor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
kun
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or