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!