How to automatically resize TStringGrid row (DefaultRowHeight) to match the height of the font used? I do something like
Grid.DefaultRowHeight:= Grid.Canvas.TextHeight('X') + 4;
but it is not working. For small fonts, the height of the rows is way too big.
Update:
It seems to be actually a problem with program's logic. If I change the font multiple times, the current height of the row matches the size of the font from previous font change event (it is one step behind).
I use this code to intercept font's size change:
procedure TStrGrid.CMFontChanged(var Message: TMessage);
begin
inherited; // let TControl react first
DefaultRowHeight:= Canvas.TextHeight('ApApM')+ 4;
end;
It acts as if the procedure will be:
begin
DefaultRowHeight:= Canvas.TextHeight('ApApM')+ 4;
inherited;
end;
(like first it changes the height, then it actually sets the correct font size - therefore the height is one step behind)