Zooming In on a Selection (C++ Builder 3.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.

void __fastcall TForm1::LEAD1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
LEAD1->AutoRubberBand = TRUE;
LEAD1->MousePointer = 2;
}

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

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

    LEAD1->MousePointer = 0;
    zoomleft = LEAD1->RubberBandLeft;
    zoomtop = LEAD1->RubberBandTop;
    zoomwidth = LEAD1->RubberBandWidth;
    zoomheight = LEAD1->RubberBandHeight;
    LEAD1->ZoomToRect(zoomleft, zoomtop, zoomwidth, zoomheight);
    LEAD1->ForceRepaint();
}

4. Run your program to test it.