Delphi의 드로잉 기능[15] - 문자의 높이와 너비:Canvas.TextExtent

1288 단어 Delphi

procedure TForm1.Button1Click(Sender: TObject);
var
  str: string;
  wh: TSize;
  w,h: Integer;
begin
  {     Canvas.TextWidth、Canvas.TextHeight}
  str := ' ';
  w := Canvas.TextWidth(str);
  h := Canvas.TextHeight(str);
  ShowMessage(Format('  : %d;   : %d', [w,h])); {  : 12;   : 13}

  {     ,               }
  str := '  ';
  w := Canvas.TextWidth(str);
  h := Canvas.TextHeight(str);
  ShowMessage(Format('  : %d;   : %d', [w,h])); {  : 24;   : 13}

  {Canvas.TextExtent                 ,           TSize   }
  wh := Canvas.TextExtent(str);
  w := wh.cx;
  h := wh.cy;
  ShowMessage(Format('  : %d;   : %d', [w,h])); {  : 24;   : 13}

  {       ,              }
  Canvas.Font.Size := 16;
  wh := Canvas.TextExtent(str);
  w := wh.cx;
  h := wh.cy;
  ShowMessage(Format('  : %d;   : %d', [w,h])); {  : 42;   : 25}

  {Font.Height      }
  Canvas.Font.Height := 32;
  wh := Canvas.TextExtent(str);
  w := wh.cx;
  h := wh.cy;
  ShowMessage(Format('  : %d;   : %d', [w,h])); {  : 52;   : 32}
end;

 

좋은 웹페이지 즐겨찾기