Board index » cppbuilder » Image gallery (StringGrid)?

Image gallery (StringGrid)?


2007-03-14 03:16:14 AM
cppbuilder52
Hi!
I want to do an image gallery like a product list in the web sites.
Is the best way using the StringGrid? How can I load each image to the each
cell?
Thank you.
 
 

Re:Image gallery (StringGrid)?

"Alexandre Paulino" < XXXX@XXXXX.COM >wrote in message
Quote
Is the best way using the StringGrid?
No. A TDrawGrid would be better. Or a TListView in vsIcon mode.
Quote
How can I load each image to the each cell?
If you use a TStringGrid or a TDrawGrid, then have to use the
OnDrawCell event to manually draw each cell. Which means you have to
store the actual images somewhere else that you can reach when needed.
Gambit
 

Re:Image gallery (StringGrid)?

"Alexandre Paulino" < XXXX@XXXXX.COM >wrote:
Quote

[...] Is the best way using the StringGrid?
As Gambit noted, a TDrawGrid is a better choice because a
TStringGrid has overhead that you don't need - except that
it does have the Objects property implemented and that can
be used to associate the TBitmap with each cell.
Quote
How can I load each image to the each cell?
You can not. The best that you can do is setup some way
for you to be able to determine which image to draw at
what moment. To know when an image needs drawing, set the
grid's DefaultDrawing property to false and add an OnDrawCell
event which will be called for each cell seperately when ever
that cell needs to be painted and the paramater list for the
event contains all of the information that you need to know
for drawing that cell.
If you were to setup a 2D array of the images that correspond
with the grids Cols and Rows count, you can use the ACol and
ARow parameters as an index into the array to get the image
for that cell. Then you can use the ARect parameter with
TCanvas::CopyRect to paint the image.
The problems that I see with this approach is image sizes
and cell sizes. Unless all of the images are exactly the
same, some images will be clipped *or* you're going to have
to tinker away at setting each individual cell's size and
that may not always be sufficient.
If your goal is to mimic the web pages that I've seen, I
would go for using a TPaintBox where you add an OnPaint
event to it and do all of the drawing in there. Again, if
you use TCanvas::CopyRect, you'll get great performance and
you'll also be able to tweek the appearance by adding what
ever you like without the restrictions imposed by using a
grid (or any other control for that matter). In addition,
if the page needs to be scrolled, just add the TPaintBox
to a TScrollBox.
~ JD
 

{smallsort}

Re:Image gallery (StringGrid)?

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
As Gambit noted, a TDrawGrid is a better choice because
a TStringGrid has overhead that you don't need - except
that it does have the Objects property implemented and
that can be used to associate the TBitmap with each cell.
If you use a TDrawGrid, then you can simply allocate your own array
for that. It doesn't matter where the images are stored, as long as
you have a way to associate each image with a specific cell, and can
find the image when needed.
Quote
The problems that I see with this approach is image sizes
and cell sizes. Unless all of the images are exactly the
same, some images will be clipped *or* you're going to have
to tinker away at setting each individual cell's size and
that may not always be sufficient.
Or, you could simply stretch each image to the same size in the grid.
Then it won't matter the size of the original images. You could then
provide a separate viewer form to display the image in its original
size if the user wants a closer look.
Gambit