Zooming In on a Selection (Delphi 4.0)

Take the following steps to add code that lets you select an area with a mouse, and zoom in on the selected area.

1. Start with the project that you created in Loading and Displaying an Image.

2. Code the LEAD control's MouseDown procedure as follows.

procedure TForm1.Lead1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   {enable AutoRubberBand}
   Lead1.AutoRubberBand := True;
   {Set the pointer to a crosshair}
   Lead1.MousePointer := 2;
end;

3. Code the LEAD control's RubberBand procedure as follows.

procedure TForm1.Lead1RubberBand(Sender: TObject);
var
   zoomleft, zoomtop, zoomwidth, zoomheight : single;
begin
   Lead1.MousePointer := 0;
   {Zoom in on the selection.}
   zoomleft := Lead1.RubberBandLeft;
   zoomtop := Lead1.RubberBandTop;
   zoomwidth := Lead1.RubberBandWidth;
   zoomheight := Lead1.RubberBandHeight;
   Lead1.ZoomToRect(zoomleft, zoomtop, zoomwidth, zoomheight);
   Lead1.ForceRepaint();
end;

4. Run your program to test it.