随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

//声明:
SetTextAlign(
  DC: HDC;    {设备环境句柄}
  Flags: UINT {对齐选项}
): UINT;      {返回对齐选项值; 如果返回 GDI_ERROR 表示设置失败}

//Flags 参数的可选值:
TA_NOUPDATECP = 0;    {每一次文本输出后, 不更新当前位置}
TA_UPDATECP   = 1;    {每一次文本输出后, 更新当前位置}
TA_LEFT       = 0;    {起始于文本外接矩形左边}
TA_RIGHT      = 2;    {起始于文本外接矩形右边}
TA_CENTER     = 6;    {起始于文本外接矩形的水平中心}
TA_TOP        = 0;    {起始于文本外接矩形顶边}
TA_BOTTOM     = 8;    {起始于文本外接矩形底边}
TA_BASELINE   = 24;   {起始于文本基线}
TA_RTLREADING = $100; {文本顺序从右到左, 只对特殊语种}

VTA_BASELINE  = TA_BASELINE; {垂直基线}
VTA_LEFT      = TA_BOTTOM;
VTA_RIGHT     = TA_TOP;
VTA_CENTER    = TA_CENTER;   {垂直居中}
VTA_BOTTOM    = TA_RIGHT;
VTA_TOP       = TA_LEFT;

//举例: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) RadioGroup1: TRadioGroup; RadioGroup2: TRadioGroup; procedure FormPaint(Sender: TObject); procedure RadioGroup1Click(Sender: TObject); procedure RadioGroup2Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} var H: Cardinal = 0; V: Cardinal = 0; procedure TForm1.FormPaint(Sender: TObject); var dc: HDC; x,y: Integer; const str = '万一的 Delphi 博客'; begin dc := Canvas.Handle; x := ClientWidth div 2; y := ClientHeight div 2; SetTextAlign(dc, H or V); TextOut(dc, x, y, str, Length(str)); end; procedure TForm1.RadioGroup1Click(Sender: TObject); begin case RadioGroup1.ItemIndex of 0: H := TA_LEFT; 1: H := TA_CENTER; 2: H := TA_RIGHT; end; Self.Repaint; end; procedure TForm1.RadioGroup2Click(Sender: TObject); begin case RadioGroup2.ItemIndex of 0: V := TA_TOP; 1: V := VTA_CENTER; 2: V := TA_BOTTOM; end; Self.Repaint; end; end.
//效果图:

posted on 2008-02-08 19:49  万一  阅读(...)  评论(...编辑  收藏