Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

drawgrid component

Posted on 2001-06-27
5
Medium Priority
?
245 Views
Last Modified: 2010-04-04
Hi experts,

I want to display 64 bitmaps in a 8x8 grid. Now I am searching for the right component. I am thinking of using a DrawGrid, but I am not sure if this is the right idea.

Unfortunately there is no valid statement like

drawgrid1.row1.col1.LoadFromFile:="c:\mybitmap1.bmp";
drawgrid1.row1.col2.LoadFromFile:="c:\mybitmap2.bmp";
....
drawgrid1.row8.col8.LoadFromFile:="c:\mybitmap64.bmp";


How would you solve this problem?



 
0
Comment
Question by:mathes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Author Comment

by:mathes
ID: 6232977
Of course I could use 64 Timage coponents, butthis approach is neither elegant nor efficient. I feel there should be something better...
0
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6233203
Hello,

If your images are the same size then you could try storing them in an imagelist. Then in the OnDrawCell event you could calculate an index and draw the appropriate image on the drawgrid. eg :

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  intIndex:integer;
  bmpTemp:TBitmap;
begin

  intIndex := (ACol * 8) + ARow; // calculate an index
  bmpTemp:=TBitmap.Create;
  try
    imagelist1.getbitmap(intIndex,bmpTemp); // get bitmap from imagelist
    DrawGrid1.Canvas.StretchDraw(Rect,bmpTemp); // draw the bitmap to fill the contents of the cell
  finally
    bmpTemp.Free; // free up temporary bitmap afterwards
  end;
end;

To prevent stretching of the bitmaps just set the DefaultRowHeight and DefaultColumnWidth to the same dimensions of your bitmaps.

Hope this helps

Jo
0
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6233243
Hello again...

To make that event handler a bit more generic you should change the formula for the index to read   intIndex := (ACol * DrawGrid1.ColCount) + ARow;


Jo
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6233254
You could try this:

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  Bmp : TBitmap;
begin
  Bmp := TBitmap.Create;
  Bmp.LoadFromFile('c:\mybitmap' + IntToStr(((ARow + 1) * (ACol + 1))) + '.bmp');
  DrawGrid1.Canvas.Draw(Rect.Left, Rect.Top, Bmp);
  Bmp.Free;
end;

Cheers,

Alan
0
 
LVL 9

Accepted Solution

by:
ITugay earned 400 total points
ID: 6234222
Hi mathes,

in addition, you can keep bitmaps in resource file and load images from there, then it will be always together with your project.

-----
Igor.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question