试了用memo1.font.height,但其值为负数,就算用绝对值也与实际不符,
如果用form1.font := memo1.font; 再用form1.canvas.TextHeight是可以得到,
有没有不借助其它组件的办法呢?

解决方案 »

  1.   

    字体高度正值是单元高度,为0是让Windows自定决定需多高,为负是实际图形部分高度
      

  2.   

    font.height=font.top-font.bottom所以为负
      

  3.   

    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.
      

  4.   

    如果你指定了Font.Size 属性,则Font.Height是负数
      

  5.   

    太好了,又有朋友帮我顶,不过我的问题还是没解决啊,
    我想取memo1上一行文本的高度,就非要把它的font指给form,再用form.canvas.textheight来取?
      

  6.   

    1.使用TCanvas.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的绝对值是不一样的