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
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Contnrs;
type
TForm1 = class(TForm)
StringGrid: TStringGrid;
AddCell: TButton;
procedure StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure AddCellClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
// Tableau de coordonnées (X/Y) des cellules à mettre en jaune
FArrayYellowCell : array of TPoint;
public
{ Déclarations publiques }
// Méthodes d'ajout de cellule
procedure addNewCell(X,Y : integer);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.addNewCell(X, Y: integer);
begin
//Ajout d'une nouvelle cellule
SetLength(FArrayYellowCell,Length(FArrayYellowCell)+1);
FArrayYellowCell[High(FArrayYellowCell)] := Point(X,Y);
end;
procedure TForm1.AddCellClick(Sender: TObject);
begin
addNewCell(1,1);
addNewCell(2,1);
addNewCell(3,1);
addNewCell(2,2);
addNewCell(2,4);
// On force le rafraichissement des cellules visibles
StringGrid.Invalidate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetLength(FArrayYellowCell,0);
end;
procedure TForm1.StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
isYellow : boolean;
i : integer;
begin
isYellow := false;
for i := 0 to High(FArrayYellowCell) do
begin
if ((FArrayYellowCell[i].X = ACol) and (FArrayYellowCell[i].Y = ARow)) then
begin
isYellow := true;
break;
end;
end;
if isYellow then
begin
{ Les cellules sélectionnées sont en Jaune }
with StringGrid.canvas do
begin
Brush.Color:=clYellow;
Rectangle(Rect.Left,Rect.Top,Rect.Right,Rect.bottom);
end;
end;
end;
end. |
Partager