Académique Documents
Professionnel Documents
Culture Documents
disclaimer
the source code of this page may not appear correctly in certain browsers
due to special characters. Have a look at the source of this HTML page
with notepad instead
The text was copy-pasted from the Delphi 2 online help, where it is spread
over several chapters
Dragging and dropping of items on a form can be a handy way to enable
users
to manipulate objects in a form. You can let users drag entire
components,
or let them drag items out of components such as list boxes into other
components.
There are four essential elements to drag-and-drop operations:
Every control has a property called DragMode that controls how the
component
responds when a user begins dragging the component at run time. If
DragMode
is dmAutomatic, dragging begins automatically when the user presses a
mouse
button on the control. A more common usage is to set DragMode to
dmManual
(which is the default) and start the dragging by handling mouse-down
events.
To start dragging a control manually, call the control's BeginDrag
method.
BeginDrag takes a Boolean parameter called Immediate. If you pass
True,
dragging begins immediately, much as if DragMode were dmAutomatic. If
you
pass False, dragging does not begin until the user actually moves the
mouse
a short distance. Calling BeginDrag(False) allows the control to
accept mouse
clicks without beginning a drag operation.
You can also place conditions on whether to begin dragging, such as
checking
which button the user pressed, by testing the parameters of the mouse-
down
event before calling BeginDrag.
Example
Setting Accept to True specifies that if the user releases the mouse
button at
that point, dropping the dragged item, the application can then send a
drag-drop
event to the same control.
Setting Accept to False specifies that the application will not drop
the item
on that control. This means that a control should never have to handle
a
drag-drop event for an item it does not know how to handle.
The drag-over event includes several parameters, including the source
of the
dragging and the current location of the mouse cursor. The event
handler can
use those parameters to determine whether to accept the drop. Most
often, a
control accepts or rejects a dragged item based on the type of the
sender,
but it can also accept items only from specific instances.
Example
Dropping items
Example
Example