首页 > Windows开发 > 详细

转载:Delphi利用Windows GDI实现文字倾斜

时间:2019-10-11 01:17:05      阅读:140      评论:0      收藏:0      [点我收藏+]

Delphi利用Windows GDI实现文字倾斜 

https://my.oschina.net/u/582827/blog/232720

技术分享图片
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs;

type
  TForm1 = class(TForm)
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormPaint(Sender: TObject);
var
  FLogFont: tagLogFontW;
  hTempFont, hPrevFont: HFONT; //字体句柄
  hTempDC: HDC; //设备描述表或图形设备句柄
  TempString: string; //输出的文字
begin
  FLogFont.lfHeight := 10; //字高
  FLogFont.lfWidth := 10; //字宽
  FLogFont.lfWeight := 1;  //字体笔划粗细程度
  FLogFont.lfUnderline := 0; //没有下划线
  FLogFont.lfStrikeOut := 0; //没有删除线
  FLogFont.lfItalic := 0; //斜体效果否
  FLogFont.lfCharSet := GB2312_CHARSET; //字符集
  FLogFont.lfEscapement := 450; //倾斜度
  // FLogFont.lfOrientation := 450;  //方向与倾斜度取值同
  FLogFont.lfFaceName := 宋体; //字体名称
  //创建逻辑字体
  hTempFont := CreateFontIndirect(FLogFont);
  TempString := 测试;

  hTempDC := GetDC(Handle); //取出窗口设备的当前字体,并替换为新字体
  hPrevFont := SelectObject(hTempDC, hTempFont); //设置设备窗口的文字色彩
  SetTextColor(hTempDC, clRed);
  TextOut(hTempDC, 20, 50, PChar(TempString), Length(TempString));
  SelectObject(hTempDC, hPrevFont);
  DeleteObject(hTempFont);
  ReleaseDC(Handle, hTempDC);
end;

end.
View Code

//可以将Form1.Color = clWhite 这样Form的背景就和字体的背景一样,这样看起来效果好一些;

技术分享图片

 

转载:Delphi利用Windows GDI实现文字倾斜

原文:https://www.cnblogs.com/studycode/p/11651432.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!