Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack - special offer!

Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

WinAPI Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
cdtrrracks.com new!

Blogspot  greatis.blogspot.com

Move control at runtime - Components - Tips & Tricks - Greatis Delphi Pages

To move control at runtime use mouse events (capture mouse events to prevent default click processing):


type
  TForm1 = class(TForm)
  ...
  private
    { Private declarations }
    Dragged: Boolean;
    OldPos: TPoint;
  ...

procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if RadioGroup1.ItemIndex=0 then
  begin
    Dragged:=True;
    GetCursorPos(OldPos);
    SetCapture(Button1.Handle);
  end;
end;

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  NewPos: TPoint;
begin
  if Dragged then
    with Button1 do
    begin
      GetCursorPos(NewPos);
      Left:=Left-OldPos.X+NewPos.X;
      Top:=Top-OldPos.Y+NewPos.Y;
      OldPos:=NewPos;
    end;
end;

procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Dragged then
  begin
    ReleaseCapture;
    Dragged:=False;
  end;
end;
Related topics
Create floating Toolbar

For more
Delphi Help
Win32 programmer's reference

We recommend
Greatis Form Designer

Download source