//先来个例子:
procedure TForm1.FormPaint(Sender: TObject);
const
S = '万一的 Delphi 博客';
var
font: TFont;
begin
font := TFont.Create;
font.Name := '微软雅黑';
font.Style := [fsBold, fsItalic];
font.Color := clRed;
font.Height := 72;
Canvas.Font := font;
Canvas.TextOut(10, 10, S);
font.Free;
end;
//效果图:
//因为 Canvas 的 Font 属性就是 TFONT 类的一个实例, 所以上面的程序可以简化为:
procedure TForm1.FormPaint(Sender: TObject);
const
S = '万一的 Delphi 博客';
begin
Canvas.Font.Name := '微软雅黑';
Canvas.Font.Style := [fsBold, fsItalic];
Canvas.Font.Color := clRed;
Canvas.Font.Height := 72;
Canvas.TextOut(10, 10, S);
end;
//TFont 类的常用属性:
{Name: 字体名称}
{Color: 颜色}
{Size、Height: 字号与字体高度, 都可以设定字体大小}
{Style: 字体样式; 是个集合值, 是下面可选值或它们的组合:}
fsBold
fsItalic
fsUnderline
fsStrikeOut
{Pitch: 是字间距相关的, 有三个枚举值可选(不过我没测试出效果):}
fpDefault
fpVariable
fpFixed
{Charset: 字符集, 是个整数, 可能的值有:}
ANSI_CHARSET = 0;
DEFAULT_CHARSET = 1;
SYMBOL_CHARSET = 2;
SHIFTJIS_CHARSET = 128;
HANGEUL_CHARSET = 129;
GB2312_CHARSET = 134;
CHINESEBIG5_CHARSET = 136;
OEM_CHARSET = 255;
JOHAB_CHARSET = 130;
HEBREW_CHARSET = 177;
ARABIC_CHARSET = 178;
GREEK_CHARSET = 161;
TURKISH_CHARSET = 162;
VIETNAMESE_CHARSET = 163;
THAI_CHARSET = 222;
EASTEUROPE_CHARSET = 238;
RUSSIAN_CHARSET = 204;
{Orientation: 旋转角度, 单位是 1/10 度, 举个例子:}
//代码:
const
S = '万一的 Delphi 博客';
begin
Canvas.Font.Style := [fsBold];
Canvas.Font.Color := clRed;
Canvas.Font.Height := 32;
Canvas.Font.Orientation := 450;
Canvas.TextOut(0, ClientHeight-20, S);
end;
//效果图: