Using the Timage control in C++builder makes it easy to read and display images, but the Timage control itself cannot receive input focus or scroll bars, and the Timage control needs to be strengthened when it displays large images that are outside the range of the display area. In this paper, two kinds of methods which are most easy to realize and effective are proposed to meet the needs of different applications.
Method One: Increase the scroll bar.
Adding scroll bars can be accomplished by placing timage in the TScrollBox control. The steps are as follows:
(1), put a TScrollBox control in the form, adjust its size.
(2), set the AutoScroll property of the TScrollBox control to True.
(3), in the TScrollBox control is to place a timage control.
(4), set the properties of the Timage control: AutoSize is true,left to 0,top to 0. After the above enhancement, if the image of the timage is larger than the display window, the scroll bar will automatically appear, if the image is smaller than the display window, the scroll bar automatically disappears, realize the large image browsing.
Method Two: Image roaming.
Image roaming refers to the use of a keyboard or mouse to control the movement of the image without the scroll bar, so that any part of the image can be browsed in a smaller display area. The following is an example of mouse control.
(1), put a Tpanel control in the form, adjust its size.
(2), in the Tpanel control is to place a timage control.
(3), set the AutoSize property of the Timage control to the True,left property is the 0,top property is 0.
(4) Add two private variables to the TForm1 class definition: intix0,iy0;
(5), responding to the onmousedown and onmousemove events of the Timage control.
Void__fastcalltform1::image1mousedown (Tobject*sender,
Tmousebuttonbutton,tshiftstateshift,intx,inty)
{
Ix0=x;
Iy0=y;
}
Void__fastcalltform1::image1mousemove
(Tobject*sender,tshiftstateshift,intx,inty)
{
Intideltax,ideltay;
if (Shift.contains (Ssleft))
{
ideltax=x-ix0;
Ideltay=y-iy0;
if (Ideltay)
image1->left+=ideltax;
if (Ideltay)
image1->top+=ideltay;
}
}
(6), while running hold down the left mouse button drag, the image will follow the move.
(7), if through keyboard control, just refer to the mouse control code, add keyboard control can be.
(8) In practical application, the boundary limit should be added to ensure the image will not be removed from the display area.
The above two methods in my software developed many times the application, the effect is very good.