The value of Height can be obtained from the point size using this formula:Font.Height = -Font.Size * Font.PixelsPerInch / 72 When the Height property has a positive value, the Size property has a negative value. When the Size property has a positive value, the Height property has a negative value.
我想取memo1上一行文本的高度,就非要把它的font指给form,再用form.canvas.textheight来取?
var
c : TCanvas;
begin
c := TCanvas.Create;
try
c.Handle := GetWindowDC(memo1.Handle); ShowMessage(IntToStr(c.TextHeight(Memo1.Lines.Text)));
finally
ReleaseDC(memo1.Handle,c.Handle);
c.Free;
end;
end;2.关于TCanvas.TextHeight 和 TFont.HeightTCanvas.TextHeight 和 TFont.Height都能返回字体的像素高度字体在设计时有一个internal leading,表示从最上端开始的间距
TCanvas.TextHeight包含了这个internal leading值
TFont.Height为负数时,不包含internal leading值
在中文字体下,internal leading为0
此时TCanvas.TextHeight 和TFont.Height的绝对值是一样的
在西文字体下,internal leading不为0
所以TCanvas.TextHeight 和TFont.Height的绝对值是不一样的