logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Paul Rayman  
#1 Posted : Wednesday, June 19, 2019 12:07:10 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,075

Thanks: 6 times
Was thanked: 124 time(s) in 121 post(s)
Question:
How can I show the text of an annotation while moving the mouse, like acrobat reader?

Answer:
Please find code below that illustrates the idea.
Code:

public class MyPdfViewer : PdfViewer
	{
        private ToolTip _tooltip = new ToolTip();

        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (Document == null)
                return;

            int pageIndex = PointInPage(e.Location);
            if (pageIndex < 0)
                return;

            var page = Document.Pages[pageIndex];
            if (page.Annots == null)
                return;

            PointF pagePoint = ClientToPage(pageIndex, e.Location);

            foreach (var annot in page.Annots)
            {
                if (!(annot is PdfTextAnnotation))
                    continue;

                var rect = annot.Rectangle;
                if(PointInRect(pagePoint, rect))
                {
                    //any code showing annotation.
                    //Tooltip for example
                    _tooltip.Show(annot.Contents, this, e.Location);
                    return;
                }
            }
            _tooltip.Hide(this);
        }

        public bool PointInRect(PointF point, FS_RECTF rect)
        {
            return !(point.X < rect.left || point.X > rect.right || point.Y < rect.bottom || point.Y > rect.top);
        }
    }
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.