How to Move a control at runtime with the mouse?



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

Post New Answer

More Delphi Interview Questions

How to tell if a form has been created (or any object)?

1 Answers  


How to Migrate a project from Delphi 1 or 2 to Delphi 3 ?

1 Answers  


How to Use Date as a Field Name ?

1 Answers  


how can i add 2 numbers using delphi console application and also windows application , compare both program , reply immediatly

1 Answers  


How to create a power function?

1 Answers  


What databases can be used with dbExpress?

1 Answers  


Is there a programmatic way to add an alias to the IDAPI.CFG?

1 Answers  


Explain ODBC Constraints ?

1 Answers  


What is the equivalent in BCB to a Pdox TCursor?

1 Answers  


How to Propagate constraints from middle-tier to client?

1 Answers  


How to DetermineDrive Type ?

1 Answers  


How to launch a control panel applet?

1 Answers  


Categories