Jump to content
IElite

Help centering image in scrollbox

Recommended Posts

I have a TW3Scrollbox on my layout. On the scrollbox I have a TW3Image, which I am trying to place below a label (fDates) and center it in the Scrollbox. The images is 150 X 150.

 

I can't seem to get the image to display in the correct position using setbounds. Its always off to the right.  

when I use showmessages to display the image width and height, those are off too.

 

How do I get the image to be sized 150 X 150 and center in the scrollbox?

 

procedure TfrmNavigation.ResizeContent;
begin


 fImage.SetBounds((fScrollBox.Content.clientWidth div 2)-75,
                   fDates.Top + fDates.Height,
                  (fScrollBox.Content.clientWidth div 2)+75,
                   fDates.Top + fDates.Height + 150);


end;


procedure TfrmNavigation.Resize;
begin
  inherited;
  if assigned(FLayout) then
  begin
    FLayout.Resize(self);
    ResizeContent;
  end;
end;


Share this post


Link to post
Share on other sites

SetBounds is (Left, Top, Width, Height), isn't it? So you wouldn't want to change the width and height of the image. Just use the values 150, 150 (or the image Width/Height properties).

 

Something like:

fImage.SetBounds((fScrollBox.Content.clientWidth - 150) div 2,
                   fDates.Top + fDates.Height,
                  150, 150);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×