Ending a Drag Operation

From RAD Studio
Jump to: navigation, search

Go Up to Implementing Drag and Drop in Controls

A drag operation ends when the item is either successfully dropped or released over a control that cannot accept it. At this point an end-drag event is sent to the control from which the drag was initiated. To enable a control to respond when items have been dragged from it, attach an event handler to the control's OnEndDrag event.

The most important parameter in an OnEndDrag event is called Target, which indicates which control, if any, accepts the drop. If Target is nil, it means no control accepts the dragged item. The OnEndDrag event also includes the coordinates on the receiving control.

In the following VCL example, a file list box handles an end-drag event by refreshing its file list.

 procedure TFMForm.FileListBox1EndDrag(Sender, Target: TObject; X, Y: Integer);
   if Target <> nil then FileListBox1.Update;
void __fastcall TFMForm::FileListBox1EndDrag(TObject * Sender, TObject * Target, int X, int Y)
if (Target)

See Also