![]() |
AW: "Optimale Breite" bei StringGrid einstellbar?
Zitat:
Delphi-Quellcode:
Benötigt system.math in der Uses-Klausel.
{!
<summary> SetGridColumnWidths sizes the columns of a grid to fit their content.</summary> <param name="Grid"> is the grid to modify. This parameter cannot be nil.</param> <param name="Columns"> specifies the columns to resize. If an empty array is passed for Columns all columns are sized, otherwise only those whos index is in Columns are sized. </param> } procedure SetGridColumnWidths(Grid: TStringGrid; const Columns: array of Integer); procedure SetGridColumnWidths(Grid: TStringGrid; const Columns: array of Integer); function ColInArray(n: Integer): Boolean; var i: Integer; begin if Length(Columns) = 0 then Result := true else begin Result := false; for i := Low(Columns) to High(Columns) do if n = Columns[i] then begin Result := true; Break; end; { If } end; { Else } end; const DEFBORDER = 8; var max, temp, i, n: Integer; begin Assert(Assigned(Grid)); Grid.Canvas.Font := Grid.Font; for n := 0 to Grid.Colcount - 1 do if ColInArray(n) then begin max := 0; for i := 0 to Grid.RowCount - 1 do begin temp := Grid.Canvas.TextWidth(Grid.Cells[n, i]) + DEFBORDER; if temp > max then max := temp; end; { For } if max > 0 then begin Grid.ColWidths[n] := Min(max, Grid.ClientWidth * 9 div 10); end; end; { If } end; {SetGridColumnWidths } |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:01 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz