Zooming In on a Selection (Delphi)

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.

Add Code to the main form's FormShow procedure as follows.

.
.
{enable AutoRubberBand}
Lead1.AutoRubberBand := True;
{Set the pointer to a crosshair}
Lead1.Cursor := crCross;
.
.

3.

Code the LEAD control's RubberBand procedure as follows.

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

4.

Run your program to test it.