logic font sample code

procedure TForm1.DrawFont(ParentHandle: HWND; x, y, fw, fh: Integer; c: string);
var
  FLogFont          : tagLogFontA;      //逻辑字体--结构体类型
  hTempFont,
    hPrevFont       : HFONT;            //字体句柄
  hTempDC           : HDC;              //设备描述表或图形设备句柄
  TempString        : string;           //输出的文字
begin
  FLogFont.lfHeight := fh;              //字高
  FLogFont.lfWidth := fw;               //字宽
  FLogFont.lfWeight := 1;               //字体笔划粗细程度
  FLogFont.lfUnderline := 0;            //没有下划线
  FLogFont.lfStrikeOut := 0;            //没有删除线
  FLogFont.lfItalic := 0;               //斜体效果否
  FLogFont.lfCharSet := GB2312_CHARSET; //字符集
  FLogfont.lfEscapement := 0;           //倾斜度
  FLogFont.lfOrientation := 0;          //方向与倾斜度取值同
  FLogFont.lfFaceName := '宋体';        //字体名称
  hTempFont := CreateFontIndirect(FLogFont); //创建逻辑字体
  TempString := c;
  hTempDC := GetDc(ParentHandle);       //取得窗口的设备句柄
  hPrevFont := SelectObject(hTempDC, hTempFont);  //取出窗口设备的当前字体,并替换为新字体
  //SetTextColor(hTempDc, clRed);         //设置设备窗口的文字色彩
  TextOut(hTempDc, x, y, PChar(TempString), Length(TempString)); //输出文字
  SelectObject(hTempDc, hPrevFont);     //恢复原有淖痔?br>  DeleteObject(hTempFont);              //删除逻辑字体
  ReleaseDC(Handle, hTempDC);           //释放设备接口
end;

var
  I                 : Integer;
  s                 : WideString;
  Len               : Integer;
  p                 : Integer;
begin
  panel1.Width := 100;
  panel1.Height := 23;
  s := '中国人';
  len := length(s);
  p := panel1.Width div len;
  for i := 1 to len do
  begin
    if (ByteType(copy(s, i,1),1) = mbSingleByte) then
      drawFont(panel1.Handle, (i - 1) * p, 0, p, panel1.Height, copy(s, i, 1))
    else
      drawFont(panel1.Handle, (i - 1) * p, 0, p div 2, panel1.Height, copy(s, i,
        1)); //中文.
  end;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值