如何从字号得到字的高度和宽度?
解决方案 »
- TMS DBAdvGrid怎么设置多行选择?
- 能将 Panel1 的底色设置成透明吗 ?
- Delphi中向SQL Server插入数据的问题,大侠帮忙看看,在线等!
- ///为什么不能在显示dbgrid时或填充数据时,设置dbgrid每列的宽度??
- mysql能否建立表间的永久关联
- 网站被黑?大家进来看看http://www.borland.con.cn/
- DBExpress怎样连接Access?
- delphi服务程序里关闭外部的exe程序
- 有没有二维码解码的空间。。。谢谢各位
- 请教:简单的Delphi向web服务器提交问题,初学,请指教!
- 请教!如何在access中存储和读取图象
- 请教各位大侠,delphi里面怎么判断一个TEdit里面输入的是一个整数?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
Procedure abc(iSize:Integer; var iWidth,iHeight:Integer);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
{ TForm1 }procedure TForm1.abc(iSize: Integer; var iWidth, iHeight: Integer);
var
iOldSize:Integer;
begin
iOldSize:=Font.Size;
try
Font.Size:=iSize; iWidth:=Canvas.TextWidth('A');
iHeight:=Canvas.TextHeight('A');
finally
Font.Size:=iOldSize;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
iSize,iWidth,iHeight:Integer;
begin
iSize:=10;
abc(iSize,iWidth,iHeight);
ShowMessage(IntToStr(iSize)+'号字 宽度:'+IntToStr(iWidth)+' 高度:'+IntToStr(iHeight));
iSize:=20;
abc(iSize,iWidth,iHeight);
ShowMessage(IntToStr(iSize)+'号字 宽度:'+IntToStr(iWidth)+' 高度:'+IntToStr(iHeight));
end;end.
begin
if not Windows.GetTextExtentPoint32(DC, PChar(S), Length(S), Result) then
Result := ErrorSize;
end;function WindowStringSize(Handle: HWND; S: String): SIZE;
var
DC: HDC;
begin
DC := GetDC(Handle);
if DC = 0 then
begin
Result := ErrorSize;
Exit;
end;
Result := StringSize(DC, S);
ReleaseDC(Handle, DC);
end;function ControlStringSize(Control: TWinControl; S: String): SIZE;
begin
Result := WindowStringSize(Control.Handle, S);
end;