TGauge文本颜色受到背景色的影响

tczy2828 2015-04-16 08:59:26


字体颜色设置相同的情况下,如图,若是背景色和覆盖色不同,字的显示效果也发生了变化
看了Gauges.pas中的代码,PaintText使用了TextRect()函数,是否与此有关,这段代码应该如何改成DrawText函数?
procedure TGauge.PaintAsText(AnImage: TBitmap; PaintRect: TRect);
var
S: string;
X, Y: Integer;
OverRect: TBltBitmap;
begin
OverRect := TBltBitmap.Create;
try
OverRect.MakeLike(AnImage);
PaintBackground(OverRect);
S := Caption;
// S := Format('%d%%', [PercentDone]);
with OverRect.Canvas do
begin
Brush.Style := bsClear;
Font := Self.Font;
Font.Color := clWhite;
with PaintRect do
begin
X := (Right - Left + 1 - TextWidth(S)) div 2;
Y := (Bottom - Top + 1 - TextHeight(S)) div 2;
end;
TextRect(PaintRect, X, Y, S);
end;
AnImage.Canvas.CopyMode := cmSrcInvert;
AnImage.Canvas.Draw(0, 0, OverRect);
finally
OverRect.Free;
end;
end;
...全文
453 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tczy2828 2015-04-17
  • 打赏
  • 举报
回复
引用 3 楼 ccrun 的回复:
Canvas 的 TextRect 方法是调用了 Windows API: ExtTextOut 实现的
不用TextRect 用DrawText怎么实现?
ccrun.com 2015-04-17
  • 打赏
  • 举报
回复
Canvas 的 TextRect 方法是调用了 Windows API: ExtTextOut 实现的
tczy2828 2015-04-17
  • 打赏
  • 举报
回复
引用 1 楼 songhtao 的回复:
文本颜色受到背景色的影响 是正常的。这是基于三基色合成的原理
但是如果是Panel Edit控件中修改背景色,它们的Caption就不会受到影响,我想要达到这样的效果
我不懂电脑 2015-04-17
  • 打赏
  • 举报
回复
文本颜色受到背景色的影响 是正常的。这是基于三基色合成的原理

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧