TDrawGrid: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TDrawGrid
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **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. | |
| 2 | + | ||
| 3 | + | Therefore, unlike other grid types, TDrawGrid requires implementing the following properties: | |
| 4 | + | ||
| 5 | + | - *OnDrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect; aState: TGridDrawState)*: Handler for the basic cell painting event | |
| 6 | + | - *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. | |
| 7 | + | ||
| 8 | + | The following simple example shows how to use *OnDrawCell*: | |
| 9 | + | ||
| 10 | + | ``` pascal | |
| 11 | + | procedure TForm1.DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Integer; | |
| 12 | + | aRect: TRect; aState: TGridDrawState); | |
| 13 | + | var | |
| 14 | + | theCanvas: TCanvas; | |
| 15 | + | begin | |
| 16 | + | theCanvas := TDrawGrid(Sender).Canvas; | |
| 17 | + | if odd(aRow) then | |
| 18 | + | begin | |
| 19 | + | if odd(aCol) then | |
| 20 | + | theCanvas.Brush.Color := clRed | |
| 21 | + | else | |
| 22 | + | theCanvas.Brush.Color := clGreen; | |
| 23 | + | end | |
| 24 | + | else | |
| 25 | + | begin | |
| 26 | + | if odd(aCol) then | |
| 27 | + | theCanvas.Brush.Color := clBlue | |
| 28 | + | else | |
| 29 | + | theCanvas.Brush.Color := clYellow; | |
| 30 | + | end; | |
| 31 | + | theCanvas.FillRect(aRect); | |
| 32 | + | end; | |
| 33 | + | ``` | |
| 34 | + | ||
| 35 | + | 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: | |
| 36 | + | ||
| 37 | + | <figure> | |
| 38 | + | <img src="TDrawGridExample.png" title="TDrawGridExample.png" /> | |
| 39 | + | <figcaption>TDrawGridExample.png</figcaption> | |
| 40 | + | </figure> | |
| 41 | + | ||
| 42 | + | ## See also | |
| 43 | + | ||
| 44 | + | - [[TStringGrid]] | |
| 45 | + | - [[TDBGrid]] | |
| 46 | + | - [[Grids Reference Page]] | |
| 47 | + | ||
| 48 | + | --- | |
| 49 | + | *From the Free Pascal wiki, page "TDrawGrid", as it stood on 2023-04-05 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
