Direct2D (10) : 文本输出初步


uses Direct2D, TypInfo;

procedure TForm1.FormCreate(Sender: TObject);
var
  f: TTextFormats;
begin
  for f := Low(TTextFormats) to High(TTextFormats) do
    CheckListBox1.Items.Add(GetEnumName(TypeInfo(TTextFormats), Ord(f)));

  CheckListBox1.Align := alRight;
  Edit1.Align := alBottom;
  Edit1.OnChange := CheckListBox1.OnClick;
end;

procedure TForm1.CheckListBox1Click(Sender: TObject);
begin
  Repaint;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  cvs: TDirect2DCanvas;
  fmt: TTextFormat;
  i: Integer;
  R: TRect;
  txt: string;
begin
  for i := 0 to CheckListBox1.Count - 1 do
    if CheckListBox1.Checked[i] then Include(fmt, TTextFormats(i));

  txt := Edit1.Text;

  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
  cvs.BeginDraw;

  cvs.TextOut(20, 20, txt); //普通文本

  cvs.Pen.Color := clGray;
  cvs.Brush.Color := clYellow;
  cvs.Font.Size := 24;
  cvs.Font.Color := clRed;
  cvs.Font.Style := [fsBold, fsItalic];
  R := Rect(20, 40, 256, 200);
  cvs.Rectangle(R);
  cvs.TextRect(R, txt, fmt); //矩形范围中的文本

  cvs.EndDraw;
  cvs.Free;
end;


效果图:

o_201103325.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值