Recent

Author Topic: [SOLVED] Dragging controls  (Read 3258 times)

Nitorami

  • Sr. Member
  • ****
  • Posts: 496
[SOLVED] Dragging controls
« on: September 27, 2017, 09:23:54 pm »
When I place a simple Label or TShape on Form1 and set its DragMode to dmAutomatic and DragMode to dkDrag, why can't I drag it ? The help says "Set to dmAutomatic to allow the user to drag this control." However when I click on it, it shows the noDrag cursor and cannot be moved.

When setting DragKind to dkDock, I can move it, even outside of Form1 but this is not what I want.
« Last Edit: October 01, 2017, 05:59:57 pm by Nitorami »

Michl

  • Full Member
  • ***
  • Posts: 226
Re: Dragging controls
« Reply #1 on: September 27, 2017, 10:29:25 pm »
You have to allow the drop for each control. The event is OnDragOver. There you have to set Accept := True. See http://wiki.freepascal.org/Drag_and_Drop_sample#Dragging_between_controls
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

Nitorami

  • Sr. Member
  • ****
  • Posts: 496
Re: Dragging controls
« Reply #2 on: September 28, 2017, 05:36:35 pm »
Alright, the cursor changes but the dragged Label still does not move. I had expected that "dmAutomatic" means that I can just move the control without further code, but the example shows there is a bit more to it... will dig into it.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Dragging controls
« Reply #3 on: September 28, 2017, 07:30:03 pm »
Alright, the cursor changes but the dragged Label still does not move. I had expected that "dmAutomatic" means that I can just move the control without further code, but the example shows there is a bit more to it... will dig into it.
drag and drop/dock is not about moving controls around their containers thing of it as dragging a file around in a file explorer you expect the file to move not the control representing it. It is there so you can code drag and drop functionality in your application that can be dragging a row on a grid to a chart and adding that row's data to the chart or dragging a file from explore in to your application and the application opening it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Dragging controls
« Reply #4 on: September 28, 2017, 11:44:53 pm »
normally all you get is a cursor indication that a drag is taking place once you
allow it to happen in the OnDrag.... events...

 When drag is complete the other event will be called and it will report the object
from which the drag started but there is no actual visual drag of the object taking
place.

 Now you can create a drag image that looks like you are dragging that object etc..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018