...Steuerelemente zur Laufzeit auf der Form bewegen?
Autor: Peter Morris
{Assign the OnMouseDown event for each component you want to move at runtime }
type
TForm1 = class(TForm)
{...}
procedure MoveControl(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private-Declarations }
public
{ Public-Declarations }
end;
end;
// In the implementation Section:
procedure TForm1.MoveControl(Sender:TObject; Button:TMouseButton;
Shift:TShiftState; X,Y:Integer);
var
TempPanel: TPanel;
Control: TControl;
begin
// Releases the mouse capture from a window
ReleaseCapture;
// If the component is a TWinControl, move it directly
if Sender is TWinControl then
TWinControl(Sender).Perform(WM_SYSCOMMAND,$F012,0)
else
try
Control := TControl(Sender);
TempPanel := TPanel.Create(Self);
with TempPanel do
begin
//Replace the component with TempPanel
Caption := '';
BevelOuter := bvNone;
SetBounds(Control.Left, Control.Top, Control.Width, Control.Height);
Parent := Control.Parent;
//Put our control in TempPanel
Control.Parent := TempPanel;
//Move TempPanel with control inside it
Perform(WM_SYSCOMMAND, $F012, 0);
//Put the component where the panel was dropped
Control.Parent := Parent;
Control.Left := Left;
Control.Top := Top;
end;
finally
TempPanel.Free;
end;
end;
printed from
www.swissdelphicenter.ch
developers knowledge base