Recent

Author Topic: Drag and drop files on control only  (Read 3195 times)

SaraT

  • Full Member
  • ***
  • Posts: 131
  • A little student
Drag and drop files on control only
« on: April 12, 2024, 06:10:16 pm »
Hi,

Is there a sample code to drag and drop .jpg and .png
files on TImage control?
Not over the form, but over the TImage only.

I would like to assign the image file to a TImage after
drag and drop the .jpg file over the TImage control.

Thanks in advance.
« Last Edit: April 12, 2024, 06:27:53 pm by SaraT »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Drag and drop files on control only
« Reply #1 on: April 12, 2024, 06:25:37 pm »
You should be more specific since there are differences on how to implement, what is source for drag operation?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

ASerge

  • Hero Member
  • *****
  • Posts: 2337
Re: Drag and drop files on control only
« Reply #2 on: April 12, 2024, 06:28:09 pm »
Not over the form, but over the TImage only.
If feedback is not required, then simply ignore the event (or issue an error message) if the mouse coordinates are outside the coordinates of the control element.
If with feedback, then it is more difficult and depends on the platform.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 538
Re: Drag and drop files on control only
« Reply #3 on: April 13, 2024, 02:00:51 pm »
I’d ask too: is it a drag/drop from outside the application, eg. by using a windows explorer,
or from a control inside the application (eg. a shelltreeview/listview)?
Basic info and examples about can be found in the wiki
https://wiki.freepascal.org/Drag_and_Drop_sample

From inside the app, a control can be allowed as drop target using the event callback OnDragOver,
Where a return variable “Accept” can be set to true or false here, so visually  indicating if a drop will be allowed or not.

From outside the app, the “OnDragOver” won’t be called. So it gets more complicated, but a “DragAccept” for a deicated control could be mimiced anyhow ---> see an example herein:
https://forum.lazarus.freepascal.org/index.php/topic,65026.msg495048.html#msg495048
Lazarus 3.6  FPC 3.2.2 Win10 64bit

440bx

  • Hero Member
  • *****
  • Posts: 4740
Re: Drag and drop files on control only
« Reply #4 on: April 13, 2024, 02:14:27 pm »
Presuming you want this for Windows only, a forum member ported Anders Melander rather nice drag and drop component suite.

You'll find information about the port and a download link at : https://forum.lazarus.freepascal.org/index.php/topic,38761.msg264283.html#msg264283

Expect spending a little time studying how the mechanism works.  Fortunately, there are a number of examples included in the port.

HTH.

ETA:

I should have mentioned that the whole thing is part of OPM therefore you can get everything you need directly from the Lazarus IDE using OPM.

« Last Edit: April 13, 2024, 02:17:40 pm by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: Drag and drop files on control only
« Reply #5 on: April 13, 2024, 03:40:03 pm »
So I assume this is different from the notification of the Application class of the OnFilesDrop etc ?
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018