Skip to content

Commit b804018

Browse files
883478 How to change cursor and add tool-tip when mouse over the uri annotation in PdfViewer
1 parent 7640320 commit b804018

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Annotations/Uri Annotation/UriAnnotation/MainWindow.xaml.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
using Syncfusion.Pdf.Graphics;
22
using Syncfusion.Pdf.Interactive;
33
using Syncfusion.Pdf.Parsing;
4-
using System;
5-
using System.Collections.Generic;
64
using System.Drawing;
75
using System.IO;
8-
using System.Linq;
9-
using System.Text;
10-
using System.Threading.Tasks;
116
using System.Windows;
127
using System.Windows.Controls;
138
using System.Windows.Controls.Primitives;
14-
using System.Windows.Data;
15-
using System.Windows.Documents;
169
using System.Windows.Input;
17-
using System.Windows.Media;
18-
using System.Windows.Media.Imaging;
19-
using System.Windows.Navigation;
20-
using System.Windows.Shapes;
2110

2211
namespace UriAnnotation
2312
{
@@ -44,36 +33,41 @@ private void BtnLoad_Click(object sender, RoutedEventArgs e)
4433

4534
//Draw the border.
4635
docView.LoadedDocument.Pages[0].Graphics.DrawRectangle(PdfPens.Red, new RectangleF(10, 10, 30, 30));
47-
48-
36+
4937
//Create a new Uri Annotation.
5038
PdfUriAnnotation uriAnnotation = new PdfUriAnnotation(new RectangleF(10, 10, 30, 30), "http://www.google.com");
5139
//Set Text to uriAnnotation.
5240
uriAnnotation.Text = "Uri Annotation";
5341
//Add this annotation to a new page.
5442
docView.LoadedDocument.Pages[0].Annotations.Add(uriAnnotation);
55-
//Save the document to disk.
43+
//Save the document and reload it into viewer.
5644
MemoryStream stream = new MemoryStream();
5745
lDoc.Save(stream);
5846
docView.Load(stream);
47+
//Get the annotation page index and bounds.
5948
annotationPageIndex = 0;
6049
annotationBounds = uriAnnotation.Bounds;
61-
//annotationBounds = convertor.ConvertToPixels(annotationBounds, PdfGraphicsUnit.Point);
50+
//Create the tooltip with content and placement target.
6251
TextBlock textBlock = new TextBlock();
6352
textBlock.Text = "Uri Annotation";
6453
tooltip.PlacementTarget = docView;
6554
tooltip.Content = textBlock;
55+
//Subscribe page mouse move event of WPF PdfViewer.
6656
docView.PageMouseMove += PdfViewer_PageMouseMove;
6757
}
6858

6959
private void PdfViewer_PageMouseMove(object sender, Syncfusion.Windows.PdfViewer.PageMouseMoveEventArgs args)
7060
{
61+
//Ensure the annotation bounds are not empty.
7162
if (annotationBounds != RectangleF.Empty)
7263
{
64+
//Convert the position from pixels to point values.
7365
float x = convertor.ConvertFromPixels((float)args.Position.X, PdfGraphicsUnit.Point);
7466
float y = convertor.ConvertFromPixels((float)args.Position.Y, PdfGraphicsUnit.Point);
67+
//Ensure the retrieved page index matches the annotation page index, and then compare the converted position value with the annotation bounds.
7568
if (args.PageIndex == annotationPageIndex && annotationBounds.Contains(x, y))
7669
{
70+
//change the cursor and set the tooltip position.
7771
docView.Cursor = Cursors.Hand;
7872
docView.ForceCursor = true;
7973
if (!tooltip.IsOpen)

0 commit comments

Comments
 (0)