Difference between revisions of "TDrawGrid"
From Lazarus wiki
Jump to navigationJump to searchJwdietrich (talk | contribs) (Adding example code) |
Jwdietrich (talk | contribs) (Correcting code for newer versions of Lazarus and the LCL) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{TDrawGrid}} | {{TDrawGrid}} | ||
− | '''TDrawGrid''' [[image:tdrawgrid.png]] is a component on the [[Additional tab]] of the [[Component Palette]]. A | + | '''TDrawGrid''' [[image:tdrawgrid.png]] is a component on the [[Additional tab]] of the [[Component Palette]]. A DrawGrid provides a tabular display of graphical information. The developer is responsible for providing the code for drawing. |
− | + | Therefore, 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 | * ''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. | + | * ''DefaultDrawing'': a boolean property deciding whether or not ''OnDrawCell'' has to handle the entire code for cell painting or if the default drawing mechanism is fired in addition. |
The following simple example shows how to use ''OnDrawCell'': | The following simple example shows how to use ''OnDrawCell'': | ||
Line 15: | Line 15: | ||
var | var | ||
theCanvas: TCanvas; | theCanvas: TCanvas; | ||
− | |||
begin | begin | ||
theCanvas := TDrawGrid(Sender).Canvas; | theCanvas := TDrawGrid(Sender).Canvas; | ||
Line 32: | Line 31: | ||
theCanvas.Brush.Color := clYellow; | theCanvas.Brush.Color := clYellow; | ||
end; | end; | ||
− | theCanvas.FillRect( | + | theCanvas.FillRect(aRect); |
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | 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: | ||
+ | |||
+ | [[File:TDrawGridExample.png]] | ||
== See also == | == See also == |
Latest revision as of 21:29, 5 April 2023
│
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. The developer is responsible for providing the code for drawing.
Therefore, 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 or if the default drawing mechanism is fired in addition.
The following simple example shows how to use OnDrawCell:
procedure TForm1.DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
var
theCanvas: TCanvas;
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(aRect);
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