ImageEn, unit iexWindowsFunctions |
|
TIEFileDragDrop
Declaration
TIEFileDragDrop = class(TComponent, IInterface, IDropTarget, IDropSource)
public
constructor Create(AOwner: TComponent);
destructor Destroy;
// Allow dropping to "DropControl"
property EnableDropping : Boolean;
// Execute dragging at cursor
function InitiateDragging(ssFilenames : TStrings; DragActions: TIEFileDragDropActions): TIEDragResult;
published
// Supported actions when dropping files
property DropActions : TIEFileDragDropActions;
// Control to receive dropped files
property DropControl : TWinControl;
// Whether a preview of files is shown while dragging
property ShowPreview: Boolean;
// Size of preview image
property PreviewWidth: Integer;
property PreviewHeight: Integer;
// Event that occurs as user starts dragging to our control
property OnBeginFileDrop : TNotifyEvent;
// Event that occurs while dragging over and dropping to allow effect to be customized
property OnGetDragDropEffect: TIEDragDropEffectEvent;
// Event that occurs when files are dropped
property OnFileDrop : TIEFileDropEvent;
end;
Description
Class to provide support for dragging and dropping files from/to Windows Explorer (and other applications). Used by
TImageEnFolderMView.
| Demos\Other\FileDragDrop\FileDragDrop.dpr |
Drop Example
// Enable dropping of a file onto a TImageEnView (from Windows Explorer, for example)
procedure TForm1.FormCreate(Sender: TObject);
begin
// These can also be set via published properties...
IEFileDragDrop1.DropControl := ImageEnView1;
IEFileDragDrop1.OnFileDrop := IEFileDragDrop1FileDrop;
IEFileDragDrop1.EnableDropping := True;
end;
procedure TForm1.IEFileDragDrop1FileDrop(Sender: TObject; ssFiles: TStrings; dwEffect: Integer);
begin
ImageEnView1.IO.LoadFromFile( ssFiles[0] );
end;
Drag Example
// Allow image to be dragged from a TImageEnView (to Windows Explorer, for example)
procedure TForm1.ImageEnView1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
ssFiles: TStringList;
begin
if GetKeyState(VK_LBUTTON) < 0 then // Mouse left button is down
begin
ssFiles := TStringList.Create;
ssFiles.Text := ImageEnView1.IO.Params.FileName;
IEFileDragDrop1.InitiateDragging( ssFiles, [iedaCopy] );
FreeAndNil(ssFiles);
end;
end;
TImageEnMView Example
procedure TForm1.FormCreate(Sender: TObject);
begin
AFileDrop := TIEFileDragDrop.Create(Self);
AFileDrop.DropControl := ImageEnMView1;
AFileDrop.OnFileDrop := DropFiles;
// Because we won't not explicity free the FileDrop object (let it free automatically on closure)
RegisterExpectedMemoryLeak(AFileDrop);
// Activate dropping
AFileDrop.EnableDropping := True;
end;
procedure TForm1.DropFiles(Sender: TObject; ssFiles: TStrings; dwEffect: Integer);
var
i: Integer;
aFileName: string;
begin
// Add the dropped image files to ImageEnMView
for i := 0 to ssFiles.Count - 1 do
begin
aFileName := Trim(ssFiles[i]);
ImageEnMView1.InsertImage(i, aFileName);
ImageEnMView1.ImageBottomText[i] := ExtractFileName(aFileName);
end;
ImageEnMView1.SelectedImage := 0;
end;