ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Drag&Drop From TImageEnMView
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

w2m

USA
1990 Posts

Posted - Sep 11 2014 :  17:35:58  Show Profile  Reply
I can drag and drop an image from explorer to TImageEnView with no problem, but I can not find any demos that show how to drag and drop a selected image from TImageEnMView in one application to another application with a TImageEnView.

Can anyone help with a little code or a demo?

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development

xequte

39053 Posts

Posted - Sep 12 2014 :  13:53:33  Show Profile  Reply
Hi Bill

TImageEnFolderMView supports dragging of images to explorer and other applications, so you might want to use that, or just use the code if you want to stay with TImageEnMView.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

w2m

USA
1990 Posts

Posted - Sep 12 2014 :  14:03:20  Show Profile  Reply
It turns out that this is a bit more complicated then a simple ImageEn demo and requires the use of other third-party components to facilitate the drag and drop. Anders Melander developed a good freeware Drag & Drop Component Suite, (http://melander.dk/delphi/dragdrop/) but he stopped updating it in 2010 so it will not compile with the XE versions of Delphi. So I obtained a copy of the Raize Drop Master 2 components (http://www.raize.com/DevTools/DropMaster/Default.asp).

I then built two applications:
A Target Destination Application that accepts drops from a Target Source Application.

The Target Destination Application contains a TDMGraphicTarget component and a TImageEnView component. The TDMGraphicTarget.AcceptorControl is set to ImageEnView1. Then the following code is added to the DMGraphicTarget1Drop event:
procedure TForm1.DMGraphicTarget1Drop(Sender: TObject; Acceptor: TWinControl;
  ThePicture: TPicture; X, Y: Integer);
var
  iString: string;
begin
  if Assigned(ThePicture) then
  begin
    { Assign ThePicture.bitmap to TImageEnView. }
    ImageEnView1.Bitmap.Assign(ThePicture.Bitmap);
    { Optionally stretch depending on checkbox state }
     if CheckBox1.Checked then
       ImageEnView1.Fit
     else
       ImageEnView1.Zoom := 100;
    { Show in the label what kind of object got dropped }
    case (Sender as TDMGraphicTarget).DroppedGraphicFormat of
      dgfBitmap: iString := 'Bitmap';
      dgfMetafile: iString := 'Metafile';
    else
      iString := '???'; { Should never happen! }
    end;
    Label1.caption := 'Dropped a '+ iString;
  end;
end;

The Target Source Application contains a TDMGraphicSource and a TImageEnView component. Then in the TImageEnOnbMouseDown event add the following code:
procedure TForm1.ImageEnMView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  iBitmap: TBitmap;
begin
  { Detect a drag with any button }
  if DragDetectEx(ImageEnMView1.Handle, POINT(X,Y), Button) then
  begin
    { Tell the graphic source which button we got}
    DMGraphicSource1.MouseButton := Button;
    { Make a temporary bitmap }
    iBitmap := TBitmap.Create;
    try
      { Assign the ImageEnMView1.Bitmap to the temporary bitmap }
      iBitmap.Assign(ImageEnMView1.Bitmap);
      { Now, we have a bitmap, so assign it to the graphic source's picture }
      DMGraphicSource1.Picture.Graphic := iBitmap;
      { Now do the drag! }
      DMGraphicSource1.Execute;
      { In case we made a big bitmap, let it go.  Otherwise, it will live on unnecessarily in the Picture property of the TDMGraphicSource. }
      DMGraphicSource1.Picture := nil;
    finally
      { Clean up. }
      iBitmap.Free;
    end;
  end;
end;


The Target Source Application can also drag images to other applications like Microsoft Word. Phew... it works nicely...

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

39053 Posts

Posted - Sep 13 2014 :  16:22:16  Show Profile  Reply
Hi Bill

Sorry, I misread your original post. I thought you mean dragging of files, rather than the image content. Nice work.




Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

graph_man

328 Posts

Posted - Oct 10 2018 :  15:21:33  Show Profile  Reply
Bill, thank you for your example.
Is there ability to drag-and-drop several pages from ImageEnMView (program1) to ImageEnMView (program2)?
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: