TDrawGrid
From Lazarus wiki
Revision as of 12:55, 20 October 2020 by Jwdietrich (talk | contribs) (Adding more information and a demo screenshot)
│
English (en) │
français (fr) │
русский (ru) │
TDrawGrid is a component on the Additional tab of the Component Palette. A drawgrid provides a tabular display of graphical information.
Unlike other grid types TDrawGrid requires implementing the following properties:
- OnDrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect; aState: TGridDrawState): Handler for the basic cell painting event
- DefaultDrawing: a boolean property deciding whether or not OnDrawCell has to handle the entire code for cell painting.
The following simple example shows how to use OnDrawCell:
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
var
theCanvas: TCanvas;
theRect: TRect;
begin
theCanvas := TDrawGrid(Sender).Canvas;
if odd(aRow) then
begin
if odd(aCol) then
theCanvas.Brush.Color := clRed
else
theCanvas.Brush.Color := clGreen;
end
else
begin
if odd(aCol) then
theCanvas.Brush.Color := clBlue
else
theCanvas.Brush.Color := clYellow;
end;
theCanvas.FillRect(theRect);
end;
The demonstration code in this example fills the content of the cells with different colours, depending on whether the rows or columns are even or odd:
See also