also ich habe im OnCreate der Form folgenden Code um auch später erzeugte Panels verschieben zu können
Delphi-Quellcode:
procedure TfrmMain.ControlMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
const
minWidth = 20;
minHeight = 20;
var
newPos: TPoint;
frmPoint : TPoint;
begin
if frmMain.inReposition then
begin
with TWinControl(Sender) do
begin
GetCursorPos(newPos);
if ssShift in Shift then
begin //resize
Screen.Cursor := crSizeNWSE;
frmPoint := ScreenToClient(Mouse.CursorPos);
if frmPoint.X > minWidth then
Width := frmPoint.X;
if frmPoint.Y > minHeight then
Height := frmPoint.Y;
end
else //move
begin
Screen.Cursor := crSize;
Left := Left - frmMain.oldPos.X + newPos.X;
Top := Top - frmMain.oldPos.Y + newPos.Y;
frmMain.oldPos := newPos;
end;
end;
end;
end; (*ControlMouseMove*)
procedure TfrmMain.ControlMouseUp(
Sender: TObject;
Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if frmMain.inReposition then
begin
Screen.Cursor := crDefault;
ReleaseCapture;
frmMain.inReposition := False;
end;
end; (*ControlMouseUp*)
procedure TfrmMain.ControlMouseDown(
Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if (MoveControls=true) AND
(Sender is TWinControl) then
begin
frmMain.inReposition:=True;
SetCapture(TWinControl(Sender).Handle);
GetCursorPos(frmMain.oldPos);
end;
end;
Procedure CM;
var
i : integer;
begin
for I:=0 to frmMain.ComponentCount-1 do
if frmMain.Components[I] is TPanel then
if Copy(TPanel(frmMain.Components[I]).Name,0,4)='PanCon' then
begin
TPanel(frmMain.Components[I]).OnMouseDown := frmMain.ControlMouseDown;
TPanel(frmMain.Components[I]).OnMouseMove := frmMain.ControlMouseMove;
TPanel(frmMain.Components[I]).OnMouseUp := frmMain.ControlMouseUp;
end;
end;
auf den Panels befinden sich auch die TImages