Base class for the rich user experience features of the ImageViewer.
public abstract class ImageViewerInteractiveMode Public MustInherit Class ImageViewerInteractiveMode public ref class ImageViewerInteractiveMode abstract ImageViewerInteractiveMode works with the InteractiveService object of the ImageViewer to provide rich user interface experiences when the user interacts with the viewer using mouse or touch.
ImageViewerInteractiveMode is a base abstract class: from it you can derive your own class to handle custom interaction with the viewer. For more information and for a list of the out-of-the-box modes provided by LEADTOOLS, refer to Image Viewer Interactive Modes.
ImageViewerInteractiveMode has the following functionality:
| Member | Description |
|---|---|
| WorkingCursor, IdleCursor and HitTestStateCursor | Cursor to use when the interactive mode is in an idle, working or hit-test state (for desktop browsers). |
| MouseButtons | The mouse button attached to this mode (for desktop browsers) |
To use an interactive mode, you create an instance of any of the derived classes and assign it to the viewer using one of the following methods:
ImageViewer.DefaultInteractiveMode: Assigns the interactive mode to the left mouse button on desktop browsers or default touch events on devices that support touch.
ImageViewer.InteractiveModes: Add more than one interactive mode to the viewer.
Within the derived class, attach listeners to the events of InteractiveService to perform actions based on user input. Set InteractiveEventArgs.IsHandled to true to mark the events as handled so that other interactive modes will not also respond to the events, if desired.
You can use multiple interactive modes at the same time. For example, use the following code to support panning/zooming with the left mouse button and magnify glass with the right button:
This example will create a custom ImageViewerInteractiveMode that will rotate the image when the user clicks or touches and drags on the viewer.
using Leadtools;using Leadtools.Controls;using Leadtools.Codecs;using Leadtools.Drawing;using LeadtoolsExamples.Common;using Leadtools.ImageProcessing;using Leadtools.ImageProcessing.Color;private class TransformInteractiveMode : ImageViewerInteractiveMode{public TransformInteractiveMode() :base(){this.AutoItemMode = ImageViewerAutoItemMode.AutoSet;}private Keys _scaleKeyModifier = Keys.Control;public virtual Keys ScaleKeyModifier{get { return _scaleKeyModifier; }set{// Supported is none and any modifiersswitch (value){case Keys.None:case Keys.Alt:case Keys.Shift:case Keys.Control:_scaleKeyModifier = value;break;default:throw new ArgumentException("Invalid value", "ScaleKeyModifier");}}}private Keys _rotateKeyModifier = Keys.Alt;public virtual Keys RotateKeyModifier{get { return _rotateKeyModifier; }set{// Supported is none and any modifiersswitch (value){case Keys.None:case Keys.Alt:case Keys.Shift:case Keys.Control:_rotateKeyModifier = value;break;default:throw new ArgumentException("Invalid value", "PageKeyModifier");}}}public override string Name{get { return "Transform"; }}public override int Id{get { return ImageViewerInteractiveMode.UserModeId + 3; }}public override void Start(ImageViewer imageViewer){base.Start(imageViewer);var service = base.InteractiveService;// Pan required eventsservice.DragStarted += new EventHandler<InteractiveDragStartedEventArgs>(service_DragStarted);service.DragDelta += new EventHandler<InteractiveDragDeltaEventArgs>(service_DragDelta);service.DragCompleted += new EventHandler<InteractiveDragCompletedEventArgs>(service_DragCompleted);service.DoubleTap += new EventHandler<InteractiveEventArgs>(service_DoubleTap);}public override void Stop(ImageViewer imageViewer){if (IsStarted){var service = base.InteractiveService;service.DragStarted -= new EventHandler<InteractiveDragStartedEventArgs>(service_DragStarted);service.DragDelta -= new EventHandler<InteractiveDragDeltaEventArgs>(service_DragDelta);service.DragCompleted -= new EventHandler<InteractiveDragCompletedEventArgs>(service_DragCompleted);service.DoubleTap -= new EventHandler<InteractiveEventArgs>(service_DoubleTap);base.Stop(imageViewer);}}private void service_DragStarted(object sender, InteractiveDragStartedEventArgs e){// Make sure pinch is not working, otherwise, ignore panif (!this.CanStartWork(e))return;// Make sure we are on an itemif (this.Item == null)return;e.IsHandled = true;this.OnWorkStarted(EventArgs.Empty);}private void service_DragDelta(object sender, InteractiveDragDeltaEventArgs e){if (!this.IsWorking)return;var item = this.Item;if (item == null)return;// Find out what to dovar dx = e.Change.X;var dy = e.Change.Y;if (dx == 0 && dy == 0)return;var scaleKeyModifier = this.ScaleKeyModifier;var rotateKeyModifier = this.RotateKeyModifier;var scale = (Control.ModifierKeys & scaleKeyModifier) == scaleKeyModifier;var rotate = (Control.ModifierKeys & rotateKeyModifier) == rotateKeyModifier;var imageViewer = this.ImageViewer;if (scale){Scale(imageViewer, item, dy, e.Origin);}else if (rotate){Rotate(imageViewer, item, dx, e.Origin);}else{Translate(imageViewer, item, dx, dy);}e.IsHandled = true;}private void service_DragCompleted(object sender, InteractiveDragCompletedEventArgs e){if (!this.IsWorking)return;e.IsHandled = true;OnWorkCompleted(EventArgs.Empty);}private void service_DoubleTap(object sender, InteractiveEventArgs e){// Make sure we not working alreadyif (this.IsWorking || !this.CanStartWork(e))return;// Make sure we have an itemvar item = this.Item;if (item == null)return;e.IsHandled = true;this.OnWorkStarted(EventArgs.Empty);Identity(this.ImageViewer, item);this.OnWorkCompleted(EventArgs.Empty);}private void Identity(ImageViewer imageViewer, ImageViewerItem item){item.Transform = LeadMatrix.Identity;}private void Scale(ImageViewer imageViewer, ImageViewerItem item, int dy, LeadPoint position){// ...// set scale code// ...}private void Rotate(ImageViewer imageViewer, ImageViewerItem item, int dx, LeadPoint position){// ...// set rotate code// ...}private void Translate(ImageViewer imageViewer, ImageViewerItem item, int dx, int dy){// ...// set translate code// ...}}public void ImageViewerInteractiveMode_Example(){_imageViewer.InteractiveModes.BeginUpdate();_imageViewer.InteractiveModes.Add(new TransformInteractiveMode { IsEnabled = false });//...//...//..._imageViewer.InteractiveModes.EndUpdate();}
Imports LeadtoolsImports Leadtools.ControlsImports Leadtools.CodecsImports Leadtools.DrawingImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.ColorPrivate Class TransformInteractiveMode : Inherits ImageViewerInteractiveModePublic Sub New()MyBase.New()Me.AutoItemMode = ImageViewerAutoItemMode.AutoSetEnd SubPrivate _scaleKeyModifier As Keys = Keys.ControlPublic Overridable Property ScaleKeyModifier() As KeysGetReturn _scaleKeyModifierEnd GetSet(value As Keys)' Supported is none and any modifiersSelect Case valueCase Keys.None, Keys.Alt, Keys.Shift, Keys.Control_scaleKeyModifier = valueCase ElseThrow New ArgumentException("Invalid value", "ScaleKeyModifier")End SelectEnd SetEnd PropertyPrivate _rotateKeyModifier As Keys = Keys.AltPublic Overridable Property RotateKeyModifier() As KeysGetReturn _rotateKeyModifierEnd GetSet(value As Keys)' Supported is none and any modifiersSelect Case valueCase Keys.None, Keys.Alt, Keys.Shift, Keys.Control_rotateKeyModifier = valueCase ElseThrow New ArgumentException("Invalid value", "PageKeyModifier")End SelectEnd SetEnd PropertyPublic Overrides ReadOnly Property Name() As StringGetReturn "Transform"End GetEnd PropertyPublic Overrides ReadOnly Property Id() As IntegerGetReturn ImageViewerInteractiveMode.UserModeId + 3End GetEnd PropertyPublic Overrides Sub Start(ByVal imageViewer As ImageViewer)MyBase.Start(imageViewer)Dim service As InteractiveService = MyBase.InteractiveService' Pan required eventsAddHandler service.DragStarted, AddressOf service_DragStartedAddHandler service.DragDelta, AddressOf service_DragDeltaAddHandler service.DragCompleted, AddressOf service_DragCompletedAddHandler service.DoubleTap, AddressOf service_DoubleTapEnd SubPublic Overrides Sub [Stop](ByVal imageViewer As ImageViewer)If IsStarted ThenDim service As InteractiveService = MyBase.InteractiveServiceRemoveHandler service.DragStarted, AddressOf service_DragStartedRemoveHandler service.DragDelta, AddressOf service_DragDeltaRemoveHandler service.DragCompleted, AddressOf service_DragCompletedRemoveHandler service.DoubleTap, AddressOf service_DoubleTapMyBase.Stop(imageViewer)End IfEnd SubPrivate Sub service_DragStarted(ByVal sender As Object, ByVal e As InteractiveDragStartedEventArgs)' Make sure pinch is not working, otherwise, ignore panIf (Not Me.CanStartWork(e)) ThenReturnEnd If' Make sure we are on an itemIf Me.Item Is Nothing ThenReturnEnd Ife.IsHandled = TrueMe.OnWorkStarted(EventArgs.Empty)End SubPrivate Sub service_DragDelta(ByVal sender As Object, ByVal e As InteractiveDragDeltaEventArgs)If (Not Me.IsWorking) ThenReturnEnd IfDim item As ImageViewerItem = Me.ItemIf item Is Nothing ThenReturnEnd If' Find out what to doDim dx As Integer = e.Change.XDim dy As Integer = e.Change.YIf dx = 0 AndAlso dy = 0 ThenReturnEnd IfDim scaleKey As Keys = Me.ScaleKeyModifierDim rotateKey As Keys = Me.RotateKeyModifierDim doScale As Boolean = (Control.ModifierKeys And scaleKey) = scaleKeyDim doRotate As Boolean = (Control.ModifierKeys And rotateKey) = rotateKeyDim imageViewer As ImageViewer = Me.ImageViewerIf doScale ThenScale(imageViewer, item, dy, e.Origin)ElseIf doRotate ThenRotate(imageViewer, item, dx, e.Origin)ElseTranslate(imageViewer, item, dx, dy)End Ife.IsHandled = TrueEnd SubPrivate Sub service_DragCompleted(ByVal sender As Object, ByVal e As InteractiveDragCompletedEventArgs)If (Not Me.IsWorking) ThenReturnEnd Ife.IsHandled = TrueOnWorkCompleted(EventArgs.Empty)End SubPrivate Sub service_DoubleTap(ByVal sender As Object, ByVal e As InteractiveEventArgs)' Make sure we not working alreadyIf Me.IsWorking OrElse (Not Me.CanStartWork(e)) ThenReturnEnd If' Make sure we have an itemDim item As ImageViewerItem = Me.ItemIf item Is Nothing ThenReturnEnd Ife.IsHandled = TrueMe.OnWorkStarted(EventArgs.Empty)Identity(Me.ImageViewer, item)Me.OnWorkCompleted(EventArgs.Empty)End SubPrivate Sub Identity(ByVal imageViewer As ImageViewer, ByVal item As ImageViewerItem)item.Transform = LeadMatrix.IdentityEnd SubPrivate Sub Scale(ByVal imageViewer As ImageViewer, ByVal item As ImageViewerItem, ByVal dy As Integer, ByVal position As LeadPoint)' ...' set scale code' ...End SubPrivate Sub Rotate(ByVal imageViewer As ImageViewer, ByVal item As ImageViewerItem, ByVal dx As Integer, ByVal position As LeadPoint)' ...' set rotate code' ...End SubPrivate Sub Translate(ByVal imageViewer As ImageViewer, ByVal item As ImageViewerItem, ByVal dx As Integer, ByVal dy As Integer)' ...' set translate code' ...End SubEnd ClassPublic Sub ImageViewerInteractiveMode_Example()_imageViewer.InteractiveModes.BeginUpdate()Dim mode As New TransformInteractiveModemode.IsEnabled = False_imageViewer.InteractiveModes.Add(mode)'...'...'..._imageViewer.InteractiveModes.EndUpdate()End Sub
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
