How to open a pop-up programmatically

Hello,

I am working with PDFViewCtrl. I have created a PDF and a redaction annotation on a page in that PDF. Now I would like to add my own drop-down menu when user right clicks on the annotation. This leads me to two questions:

  1. Is there a simple way to detect if the user has clicked on an annotation? My approach right now is to save the locations and dimensions of each annotation on the page and check if the mouse coordinates are in any of those rectangles. This seems computation-intensive so a built-in handler would be great.
  2. How do I open a pop-up programmatically? I’d like to have an option to open the pop-up in my own drop down menu. I have figured out how to add a pop-up to the annotation and set the contents.

Have you just started working with our PDFNet SDK? If so, we highly recommend using our PDFViewWPF class, and PDFViewWPFTools project. It is far more customizable than the older PDFViewCtrl class. All of the user interface/interaction code/logic source code is provided, so you can always accomplish what you want.

Could you confirm that you are using PDFViewCtrl, and not PDFViewWPF class, and clarify why the PDFViewWPF class does not work for you.

Thank you for your reply.

Yes, I am quite far along in the project already with PDFViewCtrl. If we decide to revamp the project for version 2, we’ll definitely go with PDFViewWPF. But if you have a sample of how to integrate PDFViewWPF into a WinForms project, I will gladly try it out.

There is a GetAnnotationAt in PDFViewCtrl that takes a set of coordinates. I tried all combinations I could think of to get this to return a valid annotation while clicking on a valid and existing annotation, but nothing worked. I tried:

  • mouse coordinates from the OnMouseUp event
  • using PointToClient
  • using PointToScreen
  • various combinations of PointToClient and OnMouseUp coordinates
  • various combinations of PointToScreen and OnMouseUp coordinates.
    I finally had to go with the solution found here but I would like to use the built-in method if possible.

I still haven’t found a way to open a popup from code. After assigning the popup’s parent to an annotation and the annotation’s popup to the created popup, I have tried:

  • popup.SetOpen(true)

  • popup.SetFlag(Annot.Flag.e_hidden, false)

  • popup.SetFlag(Annot.Flag.e_invisible, false)

… but nothing has worked. Again, I would like to open the popup when clicking an option on my custom context menu.

But if you have a sample of how to integrate PDFViewWPF into a WinForms project, I will gladly try it out.

We don’t have a ready made sample, but these are some useful links on how you can host a WPF control inside WinForms
https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-hosting-a-wpf-composite-control-in-windows-forms
https://www.codeproject.com/Articles/37360/Winforms-WPF-Interop.aspx

Otherwise, using PDFViewCtrl, to draw your own drop down menu would require intercepting the click event to prevent PDFViewCtrl from displaying anything, and then drawing your own WinForm control.

Before we get into the details, could you clarify why " like to add my own drop-down menu when user right clicks on the annotation" is important for you?

What is wrong with the existing implementation?

There may be a better solution I could offer if I knew more about your project.