Recent

Author Topic: How to check if the user is dragging any files/folders over my form?  (Read 3398 times)

rsz

  • New Member
  • *
  • Posts: 45
Hi,

I've written a GUI program to do some processing when the user drops files and folders onto the form. It works with the OnDropFiles event and processes whatever files and folders get dropped on it. To make my program a bit nicer I would like to change the look of my form when the user drags anything from the desktop over it.

We've got OnMouseEnter and OnMouseLeave events for when the cursor enters or leaves my form, but how can I check if the user is currently dragging files/folders?

I can't find any way to do this without writing widgetset specific code but maybe I'm overseeing something.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Re: How to check if the user is dragging any files/folders over my form?
« Reply #1 on: August 09, 2021, 01:56:12 am »
how can I check if the user is currently dragging files/folders?

AFAIK, when using the OnDropFiles event, there is no way to determine that.

On Windows at least, you can instead write a class which implements the IDropTarget interface, specifically its DragEnter(), DragLeave(), and Drop() methods.  And then you can assign an object instance of that class to your window using RegisterDragDrop().
« Last Edit: August 09, 2021, 05:46:30 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

rsz

  • New Member
  • *
  • Posts: 45
Re: How to check if the user is dragging any files/folders over my form?
« Reply #2 on: August 09, 2021, 07:07:18 am »
Thanks Remy, I was hoping I didn't have to write widgetset/platform specific code but it seems like it's not possible otherwise. I'll see if I can write a small class which abstracts this for the different widgetsets/platforms and only expose a simple IsDraggingFiles property or similar.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to check if the user is dragging any files/folders over my form?
« Reply #3 on: August 09, 2021, 12:38:29 pm »
If the dragged file/folders are part of your application, TControl has a Dragging property you can query.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How to check if the user is dragging any files/folders over my form?
« Reply #4 on: August 09, 2021, 01:17:28 pm »
If the dragged file/folders are part of your application, TControl has a Dragging property you can query.

That is meant for (and only works for) drag&drop of controls themselves; nothing to do at all with files/folders.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018