←Select platform

ImageViewerDragInteractiveMode Class

Summary

Drags images and floaters from an image viewer using mouse or touch, often to achieve Drag and Drop effects.

Syntax
C#
VB
C++
public class ImageViewerDragInteractiveMode : ImageViewerInteractiveMode 
Public Class ImageViewerDragInteractiveMode 
   Inherits ImageViewerInteractiveMode 
public ref class ImageViewerDragInteractiveMode : ImageViewerInteractiveMode 
Remarks

The ImageViewerDragInteractiveMode derives from ImageViewerInteractiveMode and subscribe to the following events

This mode allows you to use an ImageViewer as the source for a drag operation. The viewer will then handle initializing and updating the UI notifications when the user clicks and drags on an image or floater of an item in the viewer.

The mode works on any item in the viewer. The mode uses AutoSet to automatically detect the source item for the drag operation when the user clicks on the viewer. This is done by listening to DragStarted events.

When this event occurs, the mode first checks whether the user clicked an item (ImageViewerInteractiveMode.Item is not null). If not, it will not start a drag. Then it checks ItemPart to determine which part of the item to drag. Currently, if the value is ImageViewerItemPart.Floater, then Floater will be dragged; otherwise, ImageViewerItem.Image. If this condition is not met (The item does not have an image or a floater when ImageViewerItemPart.Floater is specified), then the operation will not start.

In the Windows Forms platform, the drag is performed using System.Windows.Forms.Control.DoDragDrop(System.Object,System.Windows.Forms.DragDropEffects). This methods requires two parameters. The first is the drag object and the second is the allowed effects.

The drag object is obtained from the item (either the image or the floater) and then the value of Format is checked as follows:

The AllowedEffects property determines which effects are allowed for the target (Copy, Move or Link). If the value of AllowedEffects is System.Windows.Forms.DragDropEffects, then the drag operation is not started. Note that if a floater image is used, the Link effect is not supported and the drag operation will be aborted. The floater must be copied or moved. System.Windows.Forms.Control.DoDragDrop(System.Object,System.Windows.Forms.DragDropEffects) is called on the current image viewer control using the data object and effects obtained in the previous step. When this method returns and the Move effect was used, then the mode will delete the image or floater from the source item. AutoDisposeImages is used to make sure the data is not freed twice. If Link was specified, then the same RasterImage reference is placed in the target item or ImageViewer. This should go into consideration when the items are disposed by the application. For target items in the same image viewer, this is typically automatically handled by AutoDisposeImages. For target items in a different image viewer, the user is responsible for resolving the conflict on which instance will free the now shared image. TargetImageViewerMode is used to determine which image viewer is supported as the target of this drag operations. The image viewer can drag an image from one item to another in the same viewer or to a different viewer in the same application when Format is RasterImage.RasterImageDataFormat is used. If System.Windows.Forms.DataFormats.Bitmap is used, the target destination can be any other control that accepts this format (and the effect) as the drop data. As System.Windows.Forms.Control.DoDragDrop(System.Object,System.Windows.Forms.DragDropEffects) is working and the user is dragging the source image, ImageViewer will fire ItemDragDrop events that allows the user to modify the drop operation or cancel the operation. The event data contains the following members:

Member Description
SourceImageViewer
The image viewer that initiated the drag event. This is the same ImageViewer currently attached to ImageViewerDragInteractiveMode
TargetImageViewer
The current target image viewer for this drop operation. This changes as the user drags on the application if more than one image viewer exists. It can be null if the object is not currently over an image viewer object and the same value as SourceImageViewer if the item is being dragged over the same viewer (if supported)
Operation
Current drag operation such as Enter, Over, Leave or Drop
Location
Current location of the drag item in relation to TargetImageViewer
SourceItem
The item in SourceImageViewer that originated the operation
TargetItem
The item in TargetImageViewer that will currently be the target for the drop operation. It can be null if the image viewer does not have any items or if the object is not on top of any item boundary
Effect
Current effect, change this to update the cursor
Format
The format of the data object
Abort
Allows the user to cancel the operation
The example code shows how to intercept the drag operation calls. For more information, refer to Image Viewer Interactive Modes and Image Viewer Drag and Drop.

Example
C#
VB
using Leadtools; 
using Leadtools.Controls; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
_imageViewer.InteractiveModes.BeginUpdate(); 
ImageViewerDragInteractiveMode dragMode = new ImageViewerDragInteractiveMode(); 
dragMode.AllowedEffects = DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link; 
_imageViewer.InteractiveModes.Add(dragMode); 
_imageViewer.InteractiveModes.EndUpdate(); 
Imports Leadtools 
Imports Leadtools.Controls 
Imports Leadtools.Codecs 
Imports Leadtools.Drawing 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
 
_imageViewer.InteractiveModes.BeginUpdate() 
Dim dragMode As ImageViewerDragInteractiveMode = New ImageViewerDragInteractiveMode() 
dragMode.AllowedEffects = DragDropEffects.Copy Or DragDropEffects.Move Or DragDropEffects.Link 
_imageViewer.InteractiveModes.Add(dragMode) 
_imageViewer.InteractiveModes.EndUpdate() 
Requirements
Target Platforms
Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Controls Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.