简体   繁体   中英

C# WinForm custom control events not trigger

I am developing a project in visual studio using Winform.

A part of project contains displaying pdf files. I am using opensource library installed via nuget - PfiumViewer by Pieter van Ginkel

The loading and everything works fine but no clicks events are firing.

I have checked the events with all other control it works fine but no events are fired of pdfviewer.

Below is my code to load the viewer. I'm even selecting the pdfviewer.

        pdfViewer1.Document?.Dispose();
        pdfViewer1.Document = OpenDocument(file_path);
        pdfViewer1.Select();

Here is the code I want to fire with the mousemove event

               private void pdfViewer1_MouseMove(object sender, MouseEventArgs e)
    {
        textBox2.Text = (pdfViewer1.Renderer.Page + 1).ToString();
    }

Below is the code generated in my designer.cs

this.pdfViewer1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pdfViewer1_MouseMove);

What am I missing or what I need to do to trigger the event?

The PdfViewer class contains two child-controls, a TreeView that shows the bookmarks and the PdfRenderer part, where the pdf is shown. If you want events that are happening in the renderer, attach your method to the events of the PdfRenderer , which is exposed as the Renderer property.

If you want to show the page number, you can try the DisplayRectangleChanged event, which is fired when the visible part within the renderer is changed. This is also how it is done in PdfiumViewers example project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM