I wrote a program to display a picture using Delphi 5.
>Target:
Put a image in a scrollbox. Hope the image locates at the center of the scrollbox, when the size of image is larger than the size of scrollbox, the scrollbox will display scroll bar.
>I did as below:
///----------
//set
image1.align:=alnone;
image1.scretch:=true;
image1.autosize:=true;
// add coeds in FORMCREATE and SCROLLBOX ONRESIZE:
var
imagetop,imageleft:integer
;
begin
imagetleft:=trunc(scrollbo
x1.width/2
)-trunc (image1.width/2);
if imageleft>0 then image1.left :=imageleft
else image1.left:=0;
imagetop:=trunc(scrollbox1
.height/2)
-trunc(ima
ge1.height
/2);
if h>0 then image1.top :=imagetop
else image1.top:=0;
Image1.width:=Image1.pictu
re.width ;
Image1.height:=Image1.pict
ure.height
;
//...
end;
>Problem:
It is true that the image displays at the center of scrollbox, and when the size of image is larger than the size of scrollbox, the scrollbox also displays the scroll bar, but the image can not move!
Can anyone help me?
Thanks
Start Free Trial