Automatic pan when mouse going outside zoompanel
#3
Here is a simple example of how to achieve that:

Code:
           // When mouse button is pressed (we are drawing) and mouse goes outside ZoomPanel,
           // we want to move into the direction of the mouse
           var zoomPanelPosition = e.GetPosition(ZoomPanel1);
           double dx, dy;

            if (zoomPanelPosition.X < 0)
                dx = zoomPanelPosition.X; // left of ZoomPanel
            else if (zoomPanelPosition.X > ZoomPanel1.ActualWidth)
                dx = zoomPanelPosition.X - ZoomPanel1.ActualWidth; // Right of ZoomPanel
            else
                dx = 0; // inside ZoomPanel

            if (zoomPanelPosition.Y < 0)
                dy = zoomPanelPosition.Y; // Above of ZoomPanel
            else if (zoomPanelPosition.Y > ZoomPanel1.ActualHeight) 
                dy = zoomPanelPosition.Y - ZoomPanel1.ActualHeight; // Below of ZoomPanel
            else
                dy = 0; // inside ZoomPanel

           if (dx != 0 || dy != 0)
               ZoomPanel1.TranslateNow(-dx * 0.01, -dy * 0.01); // Reduce the speed of movement so that the user has more control

To see this in action, add the code to the PaintCanvas_MouseMove method in the UseCases/PainterSample.xaml.cs file in the ZoomPanel samples project.

Note that this only works when the CaptureMouse method is called (in PaintCanvas_MouseLeftButtonDown method) - this way the element can get mouse events when the mouse goes out of its borders and even out of the application. In this case, no other control will get mouse events.
Andrej Benedik
  


Messages In This Thread
RE: Automatic pan when mouse going outside zoompanel - by abenedik - 03-05-2018, 03:03 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)