←Select platform

ImageViewerPanZoomInteractiveMode Class

Summary

Provides interactive pan and zoom user interface functionality to an ImageViewer.

Syntax
C#
Objective-C
C++/CLI
public class ImageViewerPanZoomInteractiveMode : ImageViewerInteractiveMode 
@interface LTImageViewerPanZoomInteractiveMode : LTImageViewerInteractiveMode<NSCoding> 
public ref class ImageViewerPanZoomInteractiveMode : ImageViewerInteractiveMode 
Remarks

ImageViewerPanZoomInteractiveMode derives from ImageViewerInteractiveMode and adds support for interactive pan and zoom (scale) user interface functionality to an ImageViewer.

This mode subscribes to the following events of the InteractiveService:

When used on a platform that support touch events (such as a mobile phone or a tablet), this object allows you to perform functionality such as panning and zooming with one finger or zooming using a "pinch" two fingers gesture as follows:

Functionality Members

Pan the image on the viewer using one finger (press and drag to pan) and zoom the image on the viewer using two fingers "pinch" gesture (press two fingers and drag both to zoom). This is the default behavior

Set EnablePan to true, EnableZoom to true and EnablePinchZoom to true (all default values).

Pan the image on the viewer using one finger (press and drag to pan). No zoom.

Set EnablePan to true and EnableZoom to false.

Zoom the image on the viewer using one finger (press and drag to zoom). No pan

Set EnablePan to false, EnableZoom to true and EnablePinchZoom to false.

Zoom the image on the viewer using two fingers "pinch" gesture (press two fingers and drag both to zoom). No pan.

Set EnablePan to false, EnableZoom to true and EnablePinchZoom to true.

When used on a platform that support mouse (such as a desktop), this object allows you to perform functionality such as panning and zooming with the mouse and modifier keys as follows:

Functionality Members

Pan the image on the viewer using the mouse (press and drag to pan). If the modifier key is pressed, then zoom the image on the viewer instead. This is the default behavior

Set EnablePan to true, EnableZoom to true and ZoomKeyModifier to the modifier key, such as System.Windows.Forms.Keys. (all default values).

Pan the image on the viewer using the mouse (press and drag to pan). No zoom.

Set EnablePan to true and EnableZoom to false.

Zoom the image on the viewer using the mouse (press and drag to zoom). No pan

Set EnablePan to false, EnableZoom to true and ZoomKeyModifier to System.Windows.Forms.Keys.

Along with the above, this mode supports double tapping (or double clicking) to fit the viewer to a predefined ControlSizeMode.

Keyboard panning and zooming can also be enabled using IsKeyboardEnabled and PageKeyModifier.

Using a combination of the above, you can assign separate instances of ImageViewerPanZoomInteractiveMode each with their own options to the left and right mouse using MouseButtons.

This mode uses ImageViewer.ScrollByRestrict to pan. Hence, the rules of RestrictScroll apply to the panning performed by this mode. For example, when RestrictScroll is true, you cannot pan outside the maximum boundaries of the image using this interactive mode. When the value of RestrictScroll is false, you have unlimited pan support using this mode.

This mode uses ImageViewer.Zoom to zoom. This method accepts as a parameter the origin of the zoom operation and you can control this using the ZoomAtWorkBoundsCenter property as follows:

This mode performs the main operations in the Pan, Zoom and DoubleTapZoom protected methods. ImageViewer has an ImageViewer.MaximumScaleFactor field and a ImageViewer.MinimumScaleFactor field that define the maximum and minimum scale factor allowed. This mode uses the maximum value defined in ImageViewer.MaximumScaleFactor, but defines its own minimum value set in ImageViewerPanZoomInteractiveMode.MinimumScaleFactor. This is done to ensure that the image is always visible and cannot zoom out to an unreasonable value using this mode. ImageViewerPanZoomInteractiveMode supports inertia scrolling when performing pan. This is disabled by default and can be enabled by accessing the InertiaScrollOptions property. For more information, refer to Image Viewer Interactive Modes.

As is customary with most built-in interactive modes, this mode will set InteractiveEventArgs.IsHandled to true under the following conditions:

Additionally, InteractiveEventArgs.IsHandled may be set to true if a key press causes the viewer to scroll (through IsKeyboardEnabled and PageKeyModifier) or if DoubleTapZoom is used.

Example
C#
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
 
public void ImageViewer_Example() 
{ 
   // Create the form that holds the ImageViewer 
   new MyForm().ShowDialog(); 
} 
 
class MyForm : Form 
{ 
   public MyForm() 
   { 
      this.Size = new Size(800, 800); 
   } 
 
   // LEADTOOLS ImageViewer to be used with this example 
   private ImageViewer _imageViewer; 
   // Information label 
   private Label _label; 
 
   protected override void OnLoad(EventArgs e) 
   { 
      // Create a panel to the top 
      var panel = new Panel(); 
      panel.Dock = DockStyle.Top; 
      panel.BorderStyle = BorderStyle.FixedSingle; 
      this.Controls.Add(panel); 
 
      // Add an "Example" button to the panel 
      var button = new Button(); 
      button.Text = "&Example"; 
      button.Click += (sender, e1) => Example(); 
      panel.Controls.Add(button); 
 
      // Add a label to the panel 
      _label = new Label(); 
      _label.Top = button.Bottom; 
      _label.Width = 800; 
      _label.Text = "Example..."; 
      panel.Controls.Add(_label); 
 
      // Create the image viewer taking the rest of the form 
      _imageViewer = new ImageViewer(); 
      _imageViewer.Dock = DockStyle.Fill; 
      _imageViewer.BackColor = Color.Bisque; 
      this.Controls.Add(_imageViewer); 
      _imageViewer.BringToFront(); 
 
      // Add Pan/Zoom interactive mode 
      // Click and drag to pan, CTRL-Click and drag to zoom in and out 
      _imageViewer.DefaultInteractiveMode = new ImageViewerPanZoomInteractiveMode(); 
 
      // Load an image 
      using (var codecs = new RasterCodecs()) 
         _imageViewer.Image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp")); 
 
      base.OnLoad(e); 
   } 
 
   private void Example() 
   { 
      // Example code goes here 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.1.24
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Controls Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.