1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
ExtCtrls, Grids;
type
{ TForm1 }
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
Image3: TImage;
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
procedure StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
gBitmap : TBitmap;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
gBitMap := TBitmap.Create;
with StringGrid1 do begin
if not (goRowSelect in Options) then Options := Options + [goRowSelect];
RowCount := 20;
FixedCols := 1;
ColWidths[0] := 24;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
gBitMap.Free;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
begin
with Sender as TStringGrid do
if (aCol = 0) and (aRow >= FixedRows) then
Canvas.Draw(aRect.Left+((aRect.Right-aRect.Left-gBitmap.Width) div 2),
aRect.Top+((aRect.Bottom-aRect.Top-gBitmap.Height) div 2),gBitmap);
end;
procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol,
aRow: Integer; aState: TGridDrawState);
begin
{Ici on associe les BitMaps aux conditions}
if aCol = 0 then
with Sender as TStringGrid do
if aRow = Row then
gBitmap.assign(Form1.Image1.Picture.Bitmap)
else
if aRow mod 4 = 1 then
gBitmap.assign(Form1.Image2.Picture.Bitmap)
else
gBitmap.assign(Form1.Image3.Picture.Bitmap);
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
var CanSelect: Boolean);
begin
{Le fameux invalidate : que de temps gagné !}
with Sender as TStringGrid do
Invalidate;
end;
end. |
Partager