When SizeStyle=ssPercent
the size calculation includes a double
value (the percentage). In VCL
the result must be rounded to a whole number (= pixels). The code uses Trunc()
, presumably to assure that the number of rows fit into the GridPanel
. Then, the excess pixels (if any) are "given" to the last row.
Instead of SizeStyle=ssPercent
you can use SizeStyle=ssAbsolute
and define the row heights as number of pixels. In this case the calculation does not include float values and there's no need for rounding. In this case you can declare the height of each row e.g. 28 an if the height of GridPanel1
is 280, then all rows are of equal height.
You can select SizeStyle
in the IDE (Object Inspector) by selecting all TRowItem
in the structure pane under RowCollection
.
You can define these settings also at runtime.
Edit after comment
If you use SizeStyle=ssPercent
, you need to make a choise between the two cases you show in your question.
If you use SizeStyle=ssAbsolute
, you can use the TGridPanel1.OnResize()
event to recalculate the item heights:
procedure TForm7.GridPanel1Resize(Sender: TObject);
var
i, toth, rowh: integer;
gp: TGridPanel;
begin
gp := Sender as TGridPanel;
toth := gp.Height;
rowh := toth div gp.RowCollection.Count;
for i := 0 to gp.RowCollection.Count-1 do
gp.RowCollection.Items[i].Value := rowh;
end;
In addition, if the color of the GridPanel1
is the same as that of the form, you may want to set the GridPanel1.BevelOuter=bvNone
which hides the border line of the GridPanel1
and the empty space that appears beneath the rows (when toth
is not evenly divisable) becomes unnoticeable.