StringGrid - modificar o tamanho de uma coluna de uma stringgrid para adaptar ao tamanho do texto |
Top Previous Next |
|
// modificar o tamanho de uma coluna de uma stringgrid para adaptar ao tamanho do texto
//esta é testada e aprovada pelo Diego type TExcludeColumns = set of 0..255; //colunas que nao devem ser modificadas. [] para nenhuma.
procedure SetOptimalGridCellWidth(sg: TStringGrid; ExcludeColumns: TExcludeColumns); var i : Integer; j : Integer; max_width : Integer; begin with sg do begin Canvas.Font.Assign(Font); for i := 0 to (ColCount - 1) do begin if i in ExcludeColumns then Continue; max_width := 0; for j := 0 to (RowCount - 1) do max_width := Math.Max(max_width,Canvas.TextWidth(Cells[i,j])); if max_width > 0 then ColWidths[i] := max_width + 4 else ColWidths[i] := DefaultColWidth; end; { for } end; end; |