TDrawGrid: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 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 | 2 | ||
| 3 | 3 | Therefore, unlike other grid types, TDrawGrid requires implementing the following properties: | |
| 4 | 4 | ||
| 5 | 5 | - *OnDrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect; aState: TGridDrawState)*: Handler for the basic cell painting event | |
| 6 | 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 | 7 | ||
| 8 | 8 | The following simple example shows how to use *OnDrawCell*: | |
| 9 | 9 | ||
| 10 | 10 | ``` pascal | |
| 11 | 11 | procedure TForm1.DrawGrid1DrawCell(Sender: TObject; aCol, aRow: Integer; | |
| 12 | 12 | aRect: TRect; aState: TGridDrawState); | |
| 13 | 13 | var | |
| 14 | 14 | theCanvas: TCanvas; | |
| 15 | 15 | begin | |
| 16 | 16 | theCanvas := TDrawGrid(Sender).Canvas; | |
| 17 | 17 | if odd(aRow) then | |
| 18 | 18 | begin | |
| 19 | 19 | if odd(aCol) then | |
| 20 | 20 | theCanvas.Brush.Color := clRed | |
| 21 | 21 | else | |
| 22 | 22 | theCanvas.Brush.Color := clGreen; | |
| 23 | 23 | end | |
| 24 | 24 | else | |
| 25 | 25 | begin | |
| 26 | 26 | if odd(aCol) then | |
| 27 | 27 | theCanvas.Brush.Color := clBlue | |
| 28 | 28 | else | |
| 29 | 29 | theCanvas.Brush.Color := clYellow; | |
| 30 | 30 | end; | |
| 31 | 31 | theCanvas.FillRect(aRect); | |
| 32 | 32 | end; | |
| 33 | 33 | ``` | |
| 34 | 34 | ||
| 35 | 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 | 36 | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 37 | + |  | |
| 41 | 38 | ||
| 42 | 39 | ## See also | |
| 43 | 40 | ||
| 44 | 41 | - [[TStringGrid]] | |
| 45 | 42 | - [[TDBGrid]] | |
| 46 | 43 | - [[Grids Reference Page]] | |
| 47 | 44 | ||
| 48 | 45 | --- | |
| 49 | 46 | *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).* |
