Solved

Showing and selecting images in a TDrawGrid

Posted on 2004-05-02
4
1,396 Views
Last Modified: 2012-08-14
1. I would like to show a list of images in a drawgrid
2. I want to be able to select an image from the grid
3. I would also like to be able to select 2 images from the grid

I am starting with a list of filenames held in s string list, all the files are small JPEG files. Could someone please give me some standard code to show these images in a DrawGrid as there seems to be no useful doumentation. After I have the images showing I would like to be able to click on a cell in the drawgrid and show the picture in a TImage component or click on two cells and show the images in two TImage components.

Thanks in advance - Dan
0
Comment
Question by:seabear
  • 2
4 Comments
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 10975022
0
 
LVL 6

Expert Comment

by:Amir Azhdari
ID: 10975086
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 250 total points
ID: 10976208
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, jpeg,
  StdCtrls, ExtCtrls, Grids;

type
  TForm1 = class(TForm)
    DrawGrid1: TDrawGrid;
    Image1: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure DrawGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var jpg : TJPEGImage;
    bmp : TBitmap;
    rect : TRect;
begin
  // load the JPG
  jpg := TJPEGImage.Create;
  jpg.LoadFromFile('D:\Work\grepsearch.JPG');
  // assign in Bitmap
  bmp := TBItmap.Create;
  bmp.Assign(jpg);
  // draw in the DrawGrid;
  rect := DrawGrid1.CellRect(0, 0);
  DrawGrid1.Canvas.StretchDraw(rect, bmp);
end;

procedure TForm1.DrawGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var jpg : TJPEGImage;
    bmp : TBitmap;
    rectt : TRect;
begin
  // load the JPG
  jpg := TJPEGImage.Create;
  jpg.LoadFromFile('D:\Work\grepsearch.JPG');
  // assign in Bitmap
  bmp := TBItmap.Create;
  bmp.Assign(jpg);
  // draw in the DrawGrid;
  rectt := DrawGrid1.CellRect(0, 0);
  DrawGrid1.Canvas.StretchDraw(rectt, bmp);
end;

procedure TForm1.DrawGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
var
  rect : TRect;
begin
  rect := DrawGrid1.CellRect(ACol, ARow);
  Image1.Canvas.CopyRect(rect, DrawGrid1.Canvas, rect);
end;

end.
0
 

Author Comment

by:seabear
ID: 10999922
Thank you Azhdari and Victor,
       The code that best fits what I want is Victor's so I have accepted his answer. Thank you both for your time - Dan
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now