开发者

How to get pixel width and height of String?

How do you to use GetTextExtentPoint32W in 开发者_如何学JAVADelphi 7 to get the pixel width and height of a wide string before it is output?


You can do

procedure TForm1.FormPaint(Sender: TObject);
var
  extent: TSize;
  S: WideString;
begin
  S := 'This is the integral sign: '#$222b;
  if not GetTextExtentPoint32W(Canvas.Handle, PWideChar(S), length(S), extent) then
    RaiseLastOSError;
  TextOutW(Canvas.Handle, (Width - extent.cx) div 2, (Height - extent.cy) div 2,
    PWideChar(S), length(S));
end;

The GetTextExtentPoint32W will place the width and height in extent.cx and extent.cy, respectively.

The last line will then use TextOutW to draw the string centered both horizontally and vertically on the client area.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜