其他分享
首页 > 其他分享> > Direct2D (10) : 文本输出初步

Direct2D (10) : 文本输出初步

作者:互联网

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

posted on 2011-04-01 20:57  万一  阅读(1747)  评论(0)  编辑  收藏

标签:10,txt,20,TTextFormats,cvs,Edit1,Direct2D,文本,CheckListBox1
来源: https://blog.51cto.com/u_14617575/2745415