procedure TForm1.ScrollInView(Sender : TScrollBox; Fach: TFach);
var
Rect: TRect;
begin
if Fach =
nil then Exit;
with Sender
do
begin
Rect := Classes.Rect(trunc(Fach.x/Fach.scale),trunc(Fach.y/Fach.scale),trunc(Fach.Right/Fach.scale), trunc(Fach.Bottom/fach.scale));
Dec(Rect.Left, HorzScrollBar.Margin);
Inc(Rect.Right, HorzScrollBar.Margin);
Dec(Rect.Top, VertScrollBar.Margin);
Inc(Rect.Bottom, VertScrollBar.Margin);
Rect.Left := Rect.Left + PaintBox1.ClientOrigin.X - ClientOrigin.x;
Rect.Top := Rect.Top + PaintBox1.ClientOrigin.Y - ClientOrigin.Y;
if Rect.Left < 0
then
with HorzScrollBar
do Position := Position + Rect.Left
else if Rect.Right > ClientWidth
then
begin
if Rect.Right - Rect.Left > ClientWidth
then
Rect.Right := Rect.Left + ClientWidth;
with HorzScrollBar
do Position := Position + Rect.Right - ClientWidth;
end;
if Rect.Top < 0
then
with VertScrollBar
do Position := Position + Rect.Top
else if Rect.Bottom > ClientHeight
then
begin
if Rect.Bottom - Rect.Top > ClientHeight
then
Rect.Bottom := Rect.Top + ClientHeight;
with VertScrollBar
do Position := Position + Rect.Bottom - ClientHeight;
end;
end;
end;