Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
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

News Tips .NET Software VCL Software Partners  

Move control at runtime
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


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software