Hi
Suppose a TDrawGrid named dGrid of 5 cells in a row,
each colored differently using the following array of colors;
const defPal: array[0..4] of TColor =
(clBlack,clGray,clMaroon,clOlive,clGreen);
and a TShape called PickedColor.
On the grid the colors are assigned on DrawCell event
procedure TdGridFrm.dGridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
begin
with dGrid do
begin
canvas.brush.color := defPal[aCol] ;
canvas.FillRect(CellRect(ACol, ARow));
end;
end;
How can i 'pick' (on MouseDown) the color from a dGrid.cell to assign it to PickedColor.brush
without referring to the color Array? Without doing:
procedure TdGridFrm.dGridMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var C,R: longInt;
begin
dGrid.MouseToCell(X, Y, C, R);
PickedColor.brush.color := defPal[C];
end;
It seems that each cellRect don't have a specific canvas...
So is there a unique canvas for the entire grid?
Must we clip a rectangle from that canvas?
I have not found much examples using the drawGrid around.
Thanks