应该不可以,因为memo的高度是不定的,字多了,就只能出滚动条了,很我是看不到的
下面这个是从CSDN找到的,可得到的高度有问题:
procedure TForm1.Button1Click(Sender: TObject);
var
vControlCanvas: TControlCanvas;
begin
vControlCanvas := TControlCanvas.Create;
try
vControlCanvas.Control := Memo1;
vControlCanvas.Font.Assign(Memo1.Font);
Memo1.ClientHeight := vControlCanvas.TextHeight('|') *
(Memo1.Lines.Count +
Ord(Copy(Memo1.Lines.Text, Length(Memo1.Lines.Text), 1) = #10)) + 3;
Caption := IntToStr(vControlCanvas.TextHeight('|'));
finally
vControlCanvas.Free;
end;
end;