Страница 1 из 1
как таскать за Shape?
Добавлено: 01 ноя 2005, 22:17
maelz
Как мне перемещать компонент Shape по форме? Фигня типа
Код: Выделить всё
procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
SC_DragMove = $F012;
begin
ReleaseCapture;
Shape1.perform(WM_SysCommand, SC_DragMove, 0);
end;
не работает.
Добавлено: 01 ноя 2005, 22:56
Хыиуду
Отлавливать нажатие кнопки мыши в области shape, запоминать текущие координаты мыши, при отпускании кнопки найти разность между текущими и запомненными компонентами, полученный инкремент добавить к координатам Shape
Добавлено: 02 ноя 2005, 09:19
Duncon
Код: Выделить всё
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button1MouseUp(Sender: TObject; Button:
TMouseButton; Shift: TShiftState; X, Y: Integer);
private
{Private declarations}
public
{Public declarations}
MouseDownPoint : TPoint;
Moving : bool;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ssCtrl in Shift then
begin
SetCapture(Button1.Handle);
Moving := true;
MouseDownPoint.X := x;
MouseDownPoint.Y := Y;
end;
end;
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if Moving then
begin
Button1.Left := Button1.Left - (MouseDownPoint.x - x);
Button1.Top := Button1.Top - (MouseDownPoint.y - y);
end;
end;
procedure TForm1.Button1MouseUp(Sender: TObject; Button:
TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Moving then
begin
ReleaseCapture;
Moving := false;
Button1.Left := Button1.Left - (MouseDownPoint.x - x);
Button1.Top := Button1.Top - (MouseDownPoint.y - y);
end;
end;
[/color]
Добавлено: 24 ноя 2005, 01:57
Naeel Maqsudov
maelz, Shape1.Perform и не должно работать!
Shape1 - это не оконный объект, так что сообщение WM_SYSCOMMAND ему побоку.
(Он потомок TControl, а нам нужен потомок TWinControl)
Вместо Shape1 возьмите оконный объект на котором этот шейп лежит!
например
Form1.perform(WM_SysCommand, $f012, 0);