How to Move a control at runtime with the mouse?
Answer / Amardeep Singh Yadav
To move a control (like a TForm) at runtime with the mouse, you can capture and handle mouse events. Here is an example of how to do it:nn```delphinvarn OldX, OldY: Integer;nbeginn OldX := Self.Left; OldY := Self.Top;n // Hook up OnMouseDown event handlern Self.OnMouseDown := Form1MouseDown;nend;nnprocedure TForm1.Form1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);nbeginn OldX := X; OldY := Y;n // Hook up OnMouseMove event handlern Self.OnMouseMove := Form1MouseMove;nend;nnprocedure TForm1.Form1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);nbeginn if Assigned(Sender) thenn Self.Left := OldX + (X - OldX); Self.Top := OldY + (Y - OldY);nend;n```
| Is This Answer Correct ? | 0 Yes | 0 No |
How to tell if a form has been created (or any object)?
How to Migrate a project from Delphi 1 or 2 to Delphi 3 ?
How to Use Date as a Field Name ?
how can i add 2 numbers using delphi console application and also windows application , compare both program , reply immediatly
How to create a power function?
What databases can be used with dbExpress?
Is there a programmatic way to add an alias to the IDAPI.CFG?
Explain ODBC Constraints ?
What is the equivalent in BCB to a Pdox TCursor?
How to Propagate constraints from middle-tier to client?
How to DetermineDrive Type ?
How to launch a control panel applet?