您可以从 VCL 获得一些帮助,因为该TCanvas.TextOut
方法x
将笔 pos 的坐标增加了输出字符串的宽度:
procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.MoveTo(20, 100);
Canvas.Font.Name := 'Segoe UI';
Canvas.Font.Color := clMaroon;
Canvas.Font.Style := [];
Canvas.Font.Height := 64;
Canvas.TextOut(Canvas.PenPos.X, Canvas.PenPos.Y, 'This ');
Canvas.Font.Color := clNavy;
Canvas.Font.Style := [fsBold];
Canvas.Font.Height := 64;
Canvas.TextOut(Canvas.PenPos.X, Canvas.PenPos.Y, 'is ');
Canvas.Font.Name := 'Bookman Old Style';
Canvas.Font.Color := clBlack;
Canvas.Font.Style := [fsItalic];
Canvas.Font.Height := 64;
Canvas.TextOut(Canvas.PenPos.X, Canvas.PenPos.Y, 'a ');
Canvas.Font.Name := 'Courier New';
Canvas.Font.Color := clSilver;
Canvas.Font.Style := [];
Canvas.Font.Height := 64;
Canvas.TextOut(Canvas.PenPos.X, Canvas.PenPos.Y, 'test!');
end;
无论如何,如果您需要更高级的文本输出例程,为什么不看看DirectWrite呢?