Board index » delphi » Aligning thumbnail images in a Scrollbox

Aligning thumbnail images in a Scrollbox

I have an empty scrollbox in D3 where I'm adding thumbnail images as the
user selects jpegs.  For each image I increase Left until I reach the
right margin of the box, then reset Left and increase Top.  This works
until about three rows are full and the next addition causes the
scrollbox to scroll.  Then the thumbnails aren't aligned properly as
they are added.

What adjustment do I need to make for a scrollbox when its scrollbars
become visible?  How do I tell when that happens?

Thanks, Dave

 

Re:Aligning thumbnail images in a Scrollbox


A vertical scrollbar is added if the height of the scrollbox exceeds the
visual height. You have to take the width of a vertical scrollbar into
account when adding images horizontally.
You can get the horizontal size of a vertical scrollbar in pixels with:

function GetScrollWidth: Integer;
var
  Metrics: TNonClientMetrics;
begin
  Metrics.cbSize := SizeOf(Metrics);
  SystemParametersInfo(SPI_GETNONCLIENTMETRICS, SizeOf(Metrics), @Metrics,
0);
  Result := Metrics.iScrollWidth;
end;

"Dave Johnson" <da...@c-zone.net> schreef in bericht
news:3B4A7670.7C04F27E@c-zone.net...

Quote
> I have an empty scrollbox in D3 where I'm adding thumbnail images as the
> user selects jpegs.  For each image I increase Left until I reach the
> right margin of the box, then reset Left and increase Top.  This works
> until about three rows are full and the next addition causes the
> scrollbox to scroll.  Then the thumbnails aren't aligned properly as
> they are added.

> What adjustment do I need to make for a scrollbox when its scrollbars
> become visible?  How do I tell when that happens?

> Thanks, Dave

Re:Aligning thumbnail images in a Scrollbox


The message <3B4A7670.7C04F...@c-zone.net>
  from  Dave Johnson <da...@c-zone.net> contains these words:

Quote
> I have an empty scrollbox in D3 where I'm adding thumbnail images as the
> user selects jpegs.  For each image I increase Left until I reach the
> right margin of the box, then reset Left and increase Top.  This works
> until about three rows are full and the next addition causes the
> scrollbox to scroll.  Then the thumbnails aren't aligned properly as
> they are added.
> What adjustment do I need to make for a scrollbox when its scrollbars
> become visible?  How do I tell when that happens?
> Thanks, Dave

Use
     getsystemMetrics (SM_CXVSCROLL) //Width of vertical scroll bar
     getsystemmetrics (SM_CYHSCROLL) //Height of horizontal scrollbar

By default the scrollbars become visible when something in the scrollbox
exactly touches the edge. You can change this using the Margin property
of a scroll bar (see TControlScrollBar). Generally, the client area of a
Scrollbox is virtual, and it grows as you add stuff. The origin starts
off at the top left hand corner and drifts out of the visible area once
the scrollbars appear. If you have borders on the scroll box, you need
to allow for these.

 The scrollbars don't cover whats there they just touch it so you get
the sudden jump equal to the width of a scrollbar when they first appear.
It is important to always use the getsystemmetrics functions in
calculations because the user can change the widths of scrollbars at
any time, even while the program is running.

--
Sincerely,

Andreas Kyriacou
----------------
http://www.andrikkos.co.uk (Imagine! Image Viewer)

Other Threads