g := TGPGraphics.Create(Canvas.Handle); FontFamily := TGPFontFamily.Create(WideString(trim(MemoText.Font.Name))); iFontStyle := FontStyleRegular; if SpeedButtonBold.Down then begin iFontStyle := iFontStyle or FontStyleBold; end; if SpeedButtonItalic.Down then begin iFontStyle := iFontStyle or FontStyleItalic; end; if SpeedButtonULine.Down then begin iFontStyle := iFontStyle or FontStyleUnderline; end; gpFont := TGPFont.Create(MemoText.Font.Name, Size, iFontStyle, UnitPixel); sb := TGPSolidBrush.Create(MakeColor(255,255,255,255)); strFormat := TGpStringFormat.Create(); if BitBtnLeft.Down then begin strFormat.SetFormatFlags(StringFormatFlagsNoClip); strFormat.SetAlignment(StringAlignmentNear); end else if BitBtnCenter.Down then begin strFormat.SetFormatFlags(StringFormatFlagsNoClip or StringFormatFlagsNoFitBlackBox); strFormat.SetAlignment(StringAlignmentCenter); end else begin strFormat.SetFormatFlags(StringFormatFlagsNoClip or StringFormatFlagsNoFitBlackBox); strFormat.SetAlignment(StringAlignmentFar); end; rc_in.X := 0; rc_in.Y := 0; rc_in.Width := 100000; rc_in.Height := 100000; g.MeasureString('sfsgsf',-1,gpFont,rc_in,strFormat,rc_out); iWidth := Round(rc_out.Width+0.5); iHeight := Round(rc_out.Height+0.5); // 。以下把文字在矩形中画出来 gpOrginRectF := MakeRect(0.0, 0.0,iWidth,iHeight); g.DrawString('sfsgsf',-1, gpFont, gpOrginRectF, strFormat,sb);
FontFamily := TGPFontFamily.Create(WideString(trim(MemoText.Font.Name)));
iFontStyle := FontStyleRegular;
if SpeedButtonBold.Down then
begin
iFontStyle := iFontStyle or FontStyleBold;
end;
if SpeedButtonItalic.Down then
begin
iFontStyle := iFontStyle or FontStyleItalic;
end;
if SpeedButtonULine.Down then
begin
iFontStyle := iFontStyle or FontStyleUnderline;
end;
gpFont := TGPFont.Create(MemoText.Font.Name, Size, iFontStyle, UnitPixel);
sb := TGPSolidBrush.Create(MakeColor(255,255,255,255));
strFormat := TGpStringFormat.Create();
if BitBtnLeft.Down then
begin
strFormat.SetFormatFlags(StringFormatFlagsNoClip);
strFormat.SetAlignment(StringAlignmentNear);
end
else if BitBtnCenter.Down then
begin
strFormat.SetFormatFlags(StringFormatFlagsNoClip or StringFormatFlagsNoFitBlackBox);
strFormat.SetAlignment(StringAlignmentCenter);
end
else
begin
strFormat.SetFormatFlags(StringFormatFlagsNoClip or StringFormatFlagsNoFitBlackBox);
strFormat.SetAlignment(StringAlignmentFar);
end;
rc_in.X := 0;
rc_in.Y := 0;
rc_in.Width := 100000;
rc_in.Height := 100000;
g.MeasureString('sfsgsf',-1,gpFont,rc_in,strFormat,rc_out);
iWidth := Round(rc_out.Width+0.5);
iHeight := Round(rc_out.Height+0.5);
//
。以下把文字在矩形中画出来
gpOrginRectF := MakeRect(0.0, 0.0,iWidth,iHeight);
g.DrawString('sfsgsf',-1, gpFont, gpOrginRectF, strFormat,sb);
回答完毕
strFormat.SetFormatFlags(StringFormatFlagsNoClip or StringFormatFlagsNoFitBlackBox or StringFormatFlagsMeasureTrailingSpaces);
可是还是不行啊