gpt4 book ai didi

Windows GDI 中的 Delphi TextRect

转载 作者:行者123 更新时间:2023-12-03 15:42:30 25 4
gpt4 key购买 nike

GDI 中有 Delphi TextRect 的类似物吗?我查看了DrawText、DrawTextEx,但没有找到我需要的东西。我需要绘制进度条的百分比文本,该进度条分为两个颜色部分,例如文本的左侧部分为黑色,右侧部分为白色。就像所有进度条中通常那样。

enter image description here

感谢您的回答!

最佳答案

您正在寻找ExtTextOut功能。

示例:

procedure TForm4.FormPaint(Sender: TObject);
const
S = 'This is a sample text';
begin
ExtTextOut(Canvas.Handle, 10, 10, ETO_CLIPPED,
Rect(40, 10, 100, 100), PChar(S), length(S), nil)
end;

但我认为你真正想做的是画'NOT-coloured text' :

procedure DrawTextNOT(const hDC: HDC; const Font: TFont; const Text: string; const X, Y: integer);
begin
with TBitmap.Create do
try
Canvas.Font.Assign(Font);
with Canvas.TextExtent(Text) do
SetSize(cx, cy);
Canvas.Brush.Color := clBlack;
Canvas.FillRect(Rect(0, 0, Width, Height));
Canvas.Font.Color := clWhite;
Canvas.TextOut(0, 0, Text);
BitBlt(hDC, X, Y, Width, Height, Canvas.Handle, 0, 0, SRCINVERT);
finally
Free;
end;
end;

procedure TForm4.FormPaint(Sender: TObject);
const
S = 'This is a sample text';
var
ext: TSize;
begin
Canvas.Brush.Color := clBlack;
Canvas.FillRect(Rect(0, 0, Width div 2, Height));
Canvas.Brush.Color := clWhite;
Canvas.FillRect(Rect(Width div 2, 0, Width, Height));
ext := Canvas.TextExtent(S);

DrawTextNOT(Canvas.Handle, Canvas.Font, S, (Width - ext.cx) div 2,
(Height - ext.cy) div 2);
end;

Screenshot
(来源:rejbrand.se)

关于Windows GDI 中的 Delphi TextRect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7222520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com