ControlsTDragState (C++)
Description
This code is an OnDragOver event handler that does not allow a label control to be dropped on a panel control and stops the dragging of the label as soon as you drag the label onto the panel:
Note: Set the label's DragMode property to dmAutomatic.
Code
void __fastcall TForm1::FormDragDrop(TObject *Sender, TObject *Source, int X, int Y)
{
reinterpret_cast<TForm1 *>(Source)->Left = X;
reinterpret_cast<TForm1 *>(Source)->Top = Y;
}
void __fastcall TForm1::FormDragOver(TObject *Sender, TObject *Source, int X, int Y,
TDragState State, bool &Accept)
{
Accept = Source->ClassNameIs("TLabel");
}
void __fastcall TForm1::Panel1DragOver(TObject *Sender, TObject *Source, int X, int Y,
TDragState State, bool &Accept)
{
Accept = false;
if ((Source->ClassNameIs("TLabel")) && (State == dsDragEnter))
dynamic_cast<TLabel *>(Source)->EndDrag(false);
}
Uses
- Vcl.Controls.TDragState ( fr | de | ja )
- Vcl.Controls.TControl.OnDragDrop ( fr | de | ja )
- Vcl.Controls.TControl.OnDragOver ( fr | de | ja )