Board index » delphi » Dumb question: Movable buttons

Dumb question: Movable buttons

What do I need to do in order to create buttons (or other small objects)
that the user can move around with the mouse?

All I want to do is let the user arrange them, then read their positions.

Setting DragMode to Automatic doesn't quite do it -- the button acts like
it's draggable but it won't actually move.

--
Michael A. Covington                http://www.ai.uga.edu/faculty/covington/
Artificial Intelligence Center                                           <><
The University of Georgia                Unless specifically indicated, I am
Athens, GA 30602-7415 U.S.A.                not speaking for the University.

 

Re:Dumb question: Movable buttons


Quote
mcovi...@ai.uga.edu (Michael Covington) wrote:
>What do I need to do in order to create buttons (or other small objects)
>that the user can move around with the mouse?

You could use the auto drag and drop, and then change the button's
Left and .Right values in it's DragDrop event, but then the drag
wouldn't start until the mousepointer moves off the edge of the
button.

On the other hand, you can move the button in it's MouseMove event, as
below:

unit Unit1;
...
var
  Form1: TForm1;
  Moving  : boolean;
  x_start, y_start : integer;
...
procedure TForm1.Button1MouseDown(Sender: TObject; Button:
TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
Moving := true;
x_start := X;
y_start := Y;
end;

procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState;
X,
  Y: Integer);
begin
if Moving then
  begin
  Button1.Left := Button1.Left+X-x_start;
  Button1.Top := Button1.Top+Y-y_start;
  end;
end;

procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
Moving := false;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Moving := false;
end;

...

Good luck!

Other Threads