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

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的背景就和字体的背景一样,这样看起来效果好一些;

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