Solved

Showing and selecting images in a TDrawGrid

Posted on 2004-05-02
4
1,446 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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