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
| function GetLineHeight(aWnd :hWnd) :integer;
var
DC :hDC;
Font :hFont;
TM :TTextMetric;
begin
try
DC := GetDC(aWnd);
Font := SendMessage(aWnd, WM_GETFONT, 0, 0);
if Font <> 0 then
SelectObject(DC, Font);
GetTextMetrics(DC, TM);
Result := TM.tmHeight;
finally
ReleaseDC(aWnd, DC);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.ClientHeight := Memo1.Lines.Count *GetLineHeight(Memo1.Handle);
if Memo1.BorderStyle <> bsNone then
Memo1.ClientHeight := Memo1.ClientHeight +GetSystemMetrics(SM_CYBORDER) *2;
end; |