5,930
社区成员
发帖
与我相关
我的任务
分享

使用gdi+试试,参考以下代码
//设置对齐方式
var
g: TGPGraphics;
str: String;
fontFamily: TGPFontFamily;
font: TGPFont;
rectF: TGPRectF;
strFormat: TGPStringFormat;
sb: TGPSolidBrush;
p: TGPPen;
begin
g := TGPGraphics.Create(Canvas.Handle);
fontFamily:= TGPFontFamily.Create('Arial');
font:= TGPFont.Create(fontFamily, 12, FontStyleBold, UnitPoint);
rectF:= MakeRect(30.0, 10.0, 120.0, 140.0);
sb:= TGPSolidBrush.Create(MakeColor(255, 0, 0, 255));
strFormat:= TGPStringFormat.Create;
strFormat.SetAlignment(StringAlignmentCenter); {设置左右对齐方式}
strFormat.SetLineAlignment(StringAlignmentCenter); {设置垂直对齐方式}
str := 'wy wy wy wy wy wy wy wy wy wy wy wy wy wy wy wy wy wy';
g.DrawString(str, -1, font, rectF, strFormat, sb);
p:= TGPPen.Create(MakeColor(255, 0, 0, 0));
g.DrawRectangle(p, rectF);
fontFamily.Free;
font.Free;
strFormat.Free;
sb.Free;
p.Free;
g.Free;
end;