ControlsTDragState (Delphi)
Contents
Description
This code is a TPanel's OnDragOver event handler that will not allow a label control to be dropped on the panel 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
type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
procedure Panel1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure FormDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure FormDragDrop(Sender, Source: TObject; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
TLabel(Source).Left := X;
TLabel(Source).Top := Y;
end;
procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TLabel;
end;
procedure TForm1.Panel1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := False;
if (Source is TLabel) and (State = dsDragEnter) then
(Source as TLabel).EndDrag(False);
end;
Uses
- Vcl.Controls.TDragState ( fr | de | ja )
- Vcl.Controls.TControl.OnDragDrop ( fr | de | ja )
- Vcl.Controls.TControl.OnDragOver ( fr | de | ja )