简体   繁体   English

C#WinForm自定义控件事件未触发

[英]C# WinForm custom control events not trigger

I am developing a project in visual studio using Winform. 我正在使用Winform在Visual Studio中开发一个项目。

A part of project contains displaying pdf files. 项目的一部分包含显示pdf文件。 I am using opensource library installed via nuget - PfiumViewer by Pieter van Ginkel 我正在使用通过nuget安装的开源库-Pieter van Ginkel的PfiumViewer

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. 我已经用所有其他控件检查了事件,它可以正常工作,但没有触发pdfviewer事件。

Below is my code to load the viewer. 以下是我加载查看器的代码。 I'm even selecting the pdfviewer. 我什至选择了pdfviewer。

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

Here is the code I want to fire with the mousemove event 这是我想用mousemove事件触发的代码

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

Below is the code generated in my designer.cs 以下是我的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. PdfViewer类包含两个子控件,一个显示书签的TreeView和一个显示pdf的PdfRenderer部分。 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. 如果您想要渲染器中发生的事件,请将您的方法附加到PdfRenderer的事件中,该事件作为Renderer属性公开。

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. 如果要显示页码,可以尝试使用DisplayRectangleChanged事件,该事件在渲染器中的可见部分发生更改时触发。 This is also how it is done in PdfiumViewers example project. 这也是在PdfiumViewers示例项目中完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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