【发布时间】:2012-05-21 14:31:31
【问题描述】:
我想让一个组合框控制单选按钮的背景颜色,但单选按钮不透明。主题已启用,我将单选按钮的 parentbackground 设置为 true。
这是我得到的:
我希望通过单选按钮显示蓝色渐变,并且不使用任何颜色作为单选按钮的背景。
我正在调用这个方法,用 GDI+ 在组框上绘图:
procedure TMyRadio.PaintBackground(AParentColor : TColor; Graphics: IGPGraphics);
var
ExpandedRect : TGPRect;
Path : IGPGraphicsPath;
GradientBrush : IGPPathGradientBrush;
SurroundColors : array[0..0] of TGPColor;
begin
ExpandedRect := TGPRect.Create(ExpandBorder(BoundsRect, 10));
Path := TGPGraphicsPath.Create;
Path.AddRectangle(ExpandedRect);
GradientBrush := TGPPathGradientBrush.Create(Path);
GradientBrush.CenterColor := TGPColor.Create(255,
GetRValue(ColorToRGB(BackgroundColor)),
GetGValue(ColorToRGB(BackgroundColor)),
GetBValue(ColorToRGB(BackgroundColor))
);
SurroundColors[0].Initialize(0,
GetRValue(ColorToRGB(AParentColor)),
GetGValue(ColorToRGB(AParentColor)),
GetBValue(ColorToRGB(AParentColor))
);
GradientBrush.SetSurroundColors(SurroundColors);
Graphics.FillRectangle(GradientBrush, ExpandedRect);
end;
从覆盖的绘制函数中,单选按钮所在的组框不会通过单选按钮控件显示。我没有在其他任何地方设置单选按钮的颜色,并且在运行时我已经检查过ParentBackground = true。
【问题讨论】:
-
是否启用了双缓冲,例如
DoubleBuffered := True?有时这会导致控件出现图形问题。如果是,则通过代码或从 Object Inspector 中的父控件将其设置为 false。 -
@blobby,两种方法我都试过了。我也试过这个:stackoverflow.com/questions/2461793/… 并在没有主题的情况下运行它(在终端服务器上),它看起来很糟糕。所以无论如何我都可以选择纯色。
-
我认为这可能是第 3 方组件可能更适合您尝试做的事情的情况之一。
-
BoundsRect 如果 PaintBackground 是单选组的方法,则应该引用单选组的边界矩形。但是从您发布的图片看来,矩形是根据单选按钮的边界矩形计算的。你确定你覆盖了组框的 Paint,而不是单选按钮?
-
我使用 Dream Controls 对 XE2 稍作修改
标签: delphi radio-button transparency