Solved

Showing and selecting images in a TDrawGrid

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 169
Machine not responding during CopyFile() 3 89
Working this component WebCopy with proxy, help 3 76
CheckListBox usage 3 50
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

21 Experts available now in Live!

Get 1:1 Help Now