Zooming In on a Selection (C++ Builder)

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.

void __fastcall TForm1::Lead1RubberBand(TObject *Sender)
{
   int zoomleft, zoomtop, zoomwidth, zoomheight ;

   /*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();
}

4.

Run your program to test it.