Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.4.3
|
Leadtools.Controls Assembly > Leadtools.Controls Namespace : ImageViewerDragInteractiveMode Class |
public class ImageViewerDragInteractiveMode : ImageViewerInteractiveMode
'Declaration
Public Class ImageViewerDragInteractiveMode Inherits ImageViewerInteractiveMode
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 occur, the mode first checks if 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 Windows Forms platform, the drag is performed using DoDragDrop. 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:
If Format is RasterImage.RasterImageDataFormat, then the same source RasterImage reference is used. The object is not serialized and will be used as is. This is supported only if the drag target is in the same application.
If Format is DataFormats.Bitmap, then the mode will use RasterImageConverter.ConvertToImage to create a copy of the source image data and place it in a GDI+ Bitmap object.
No other format is supported at this time. Setting Format to any other value will throw an exception.
AllowedEffects determine which effects is allowed to the target (Copy, Move or Link). If the value of AllowedEffects is DragDropEffects.None, then the drag operation is not started. Note that if a floater image is used, then Link effect is not supported and the drag operation will be aborted. The floater must be copied or moved.
DoDragDrop 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 DataFormats.Bitmap is used, the target destination can be any other control that accepts this format (and the effect) as the drop data.
As DoDragDrop 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.
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()
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();