Repaint scheint zu funktionieren, zusätzlich muss danach noch ValidateRect aufgerufen werden, damit der störende Effekt verschwindet.
Delphi-Quellcode:
procedure TFTest.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
Diff: Integer;
ControlPos: TPoint;
ControlRect: TRect;
begin
if (ssLeft in Shift) and (Sender = Selected.Control) then
begin
ControlPos.X := Selected.Control.Left + X - Selected.Pos.X;
ControlPos.Y := Selected.Control.Top + Y - Selected.Pos.Y;
{Element im Clientbereich einsperren}
with Selected.Control.Parent.ClientRect do
begin
Diff := Right - (ControlPos.X + Selected.Control.Width);
if Diff < 0 then
ControlPos.X := ControlPos.X + Diff;
Diff := Left - ControlPos.X;
if Diff > 0 then
ControlPos.X := ControlPos.X + Diff;
Diff := Bottom - (ControlPos.Y + Selected.Control.Height);
if Diff < 0 then
ControlPos.Y := ControlPos.Y + Diff;
Diff := Top - ControlPos.Y;
if Diff > 0 then
ControlPos.Y := ControlPos.Y + Diff;
end;
with Selected.Control do
begin
if (Left <> ControlPos.X) or (Top <> ControlPos.Y) then
begin
SetBounds(ControlPos.X, ControlPos.Y, Width, Height);
Repaint;
ControlRect := BoundsRect;
ValidateRect(Parent.Handle, @ControlRect);
end;
end;
end;
end;