Know when mouse is not over page

Hello,

There is a PageMouseMove event on the PdfViewer control which fires when the mouse is being hovered over the page (https://help.syncfusion.com/windowsforms/pdf-viewer/how-to/get-mouse-position).

I'm looking for a way to know when the mouse crosses the border of the page into the background of the control (marked in the red circle below):


Can someone point me in the right direction?


5 Replies 1 reply marked as answer

DD Divya Dhayalan Syncfusion Team January 9, 2022 07:42 PM UTC

Hi Wouter, 
 
Based on the details you have provided; we understand that your requirement is to know the mouse cursor cross hover the page border. We can achieve this by using the PdfViewerControl PageMouseMove event and Page Size value. We have created a sample for your reference, and which can be downloaded from the below link, 
 
In the sample we have achieved the requirement by getting the Page size value using the LoadedDocument object. Using the LoadedDocument object get the Pages collection and size of the specific page. Using the PdfUnitConvertor converted the page size point value to pixel based on the page current rotation value. The page rotation is get using the GetPageRotation method of PageOrganizer. By comparing this page size value with the PageMouseMove event argument Position we can track the mouse move hover the border. 
 
Please check the above sample and details and let us know if you need any further assistance on this. Kindly share some more details about your requirement if our understanding about your requirement is not same. 
 
Regards, 
Divya  



WV Wouter van der Post January 10, 2022 10:02 AM UTC

Hi Divya,

Thanks for the sample project.

My requirement is a little bit different, I don't specifically need to know when the mouse is on the border, instead I need to know when the mouse is outside of the page. When I start the sample and move the mouse fast enough I can  easily cross the border without the message box showing up. Is there also an easy way to know when the mouse is located outside the page?



DD Divya Dhayalan Syncfusion Team January 11, 2022 02:41 PM UTC

Hi Wouter, 
 
Thank you for sharing more detail about your requirement. From the provided details we understand that your requirement is to know whenever the mouse cursor is outside of the PDF page. In our Pdf Viewer we do not have support to find the mouse cursor is outside of the PDF page. However, we can achieve this requirement by using the Window’s MouseMove event handler. Using the OriginalSource event argument of the MouseMove event handler we can track the mouse cursor when hover the empty area in the PdfViewerControl. Please find the below code snippet for the same. 
 
private void MainWindow_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) 
        { 
            if(e.OriginalSource is  System.Windows.Controls.ScrollViewer) 
            { 
 
            } 
        } 
 
When we mouse hover above the empty area the MouseMove event originally raised from ScrollViewer control, if we move hover the page the original source is Canvas.  
 
We have also created sample for your reference which can be downloaded from the below link, 
 
Please check the above sample and details and let us know if you need any further assistance on this.  
 
Regards, 
Divya  


Marked as answer

WV Wouter van der Post January 13, 2022 09:02 AM UTC

Hi Divya,

Never thought it would be this simple! Thanks a lot for this solution, it works perfectly.


Regards,

Wouter.



DD Divya Dhayalan Syncfusion Team January 14, 2022 05:11 AM UTC

Hi Wouter, 
 
Most welcome, we are glad that the provided solution helpful to achieve your requirement. Please let us know if you need any further assistance on this. 
 
Regards, 
Divya

Loader.
Up arrow icon