TDragState is used to specify how the mouse is moving in relation to a control.
TDragState = ( dsDragEnter, dsDragLeave, dsDragMove );
enum TDragState { dsDragEnter, dsDragLeave, dsDragMove };
TDragState describes how the mouse is moving in relation to a control that it is passing over. It has one of the following values:
Value |
Meaning |
dsDragEnter |
The mouse just moved over the control. |
dsDragLeave |
The mouse is moving off of the control. |
dsDragMove |
The mouse is moving while over the control. |
C++ Examples:
/* This code is an OnDragOver event handler that won't allow a label control to be dropped on a panel control and stops the dragging of the label as soon as the user drags the label onto the panel: Note: Set the label's DragMode property to dmAutomatic. */ 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); }
Delphi Examples:
{ This code is an OnDragOver event handler that won't allow a label control to be dropped on a panel control and stops the dragging of the label as soon as the user drags the label onto the panel: Note: Set the label's DragMode property to dmAutomatic. } 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 TForm1(Source).Left := X; TForm1(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;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|