Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
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
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.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