Bonjour,
Si cela peut vous être utile, comme je n'ai pas trouvé de code sous Lazarus réglant ce problème, je me suis basé sur la résolution d'un problème identique que j'ai rencontré récemment sur des TStringGrids. Petites vidéos win.avi et nux.avi.
Le codeLe principe est le même que pour la TStringGrid. Seul le Rect étant défini comme constante m'a obligé à utiliser une variable aRect.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 uses [...] Grids, LCLIntf {DrawText}, LCLType {DT_CALCRECT or DT_WORDBREAK}; type [...] TPublicCustomGrid = class(TCustomGrid); procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var aRect, bRect : TRect; sTmp : String; iRow : Integer; begin if Column.FieldName = 'vodesign' then begin //Colonne concernée sTmp := column.Field.DataSet.FieldByName('vodesign').AsString; iRow := DBGrid1.DataSource.DataSet.RecNo; with (Sender as TDBGrid) do begin Canvas.FillRect(Rect); Canvas.FillRect(bRect); bRect := Rect; DrawText(Canvas.Handle, PChar(sTmp), length(sTmp), bRect, DT_CALCRECT or DT_WORDBREAK); if (bRect.Bottom - bRect.Top) > DBGrid1.DefaultRowHeight then TPublicCustomGrid(DBGrid1).RowHeights[iRow] := bRect.Bottom - bRect.Top else TPublicCustomGrid(DBGrid1).RowHeights[iRow] := DBGrid1.DefaultRowHeight; aRect := Rect; {Can't assign values to const variable} DrawText(Canvas.Handle, PChar(sTmp), length(sTmp), aRect, DT_WORDBREAK); end; end; end;
Cordialement. Gilles
Testé sous Win 32 (Seven) : lazarus 0.9.31-31448 fpc-2.4.4-20110629 et Ubuntu 32 (10 & 11.04) : lazarus 0.9.31.31827 fpc 2.4.5-110730 i386
Partager