I m using BDS 2006 and would like to know if u can change the color of Group-box and radio group captions with XPmanifest present in the Project(because it is Always blue in color).
Asked
Active
Viewed 1.1k times
1 Answers
8
The only way to this is overriding the Paint method of the TGroupBox
.
Check this sample which uses a Interposer class
type
TGroupBox = class(StdCtrls.TGroupBox) //declare this before of your form definition
public
procedure Paint; override;
end;
uses
Themes;
{ TGroupBox }
procedure TGroupBox.Paint;
var
H: Integer;
R: TRect;
Flags: Longint;
CaptionRect,
OuterRect: TRect;
Size: TSize;
Box: TThemedButton;
Details: TThemedElementDetails;
begin
with Canvas do
begin
Font := Self.Font;
if ThemeControl(Self) then
begin
if Text <> '' then
begin
GetTextExtentPoint32(Handle, PChar(Text), Length(Text), Size);
CaptionRect := Rect(0, 0, Size.cx, Size.cy);
if not UseRightToLeftAlignment then
OffsetRect(CaptionRect, 8, 0)
else
OffsetRect(CaptionRect, Width - 8 - CaptionRect.Right, 0);
end
else
CaptionRect := Rect(0, 0, 0, 0);
OuterRect := ClientRect;
OuterRect.Top := (CaptionRect.Bottom - CaptionRect.Top) div 2;
with CaptionRect do
ExcludeClipRect(Handle, Left, Top, Right, Bottom);
if Enabled then
Box := tbGroupBoxNormal
else
Box := tbGroupBoxDisabled;
Details := ThemeServices.GetElementDetails(Box);
//Draw the themed frame
ThemeServices.DrawElement(Handle, Details, OuterRect);
SelectClipRgn(Handle, 0);
if Text <> '' then
begin
H := TextHeight('0');
if not UseRightToLeftAlignment then
R := Rect(8, 0, 0, H)
else
R := Rect(R.Right - Canvas.TextWidth(Text) - 8, 0, 0, H);
Flags := DrawTextBiDiModeFlags(DT_SINGLELINE);
//Now using the Windows.DrawText
DrawText(Handle, PChar(Text), Length(Text), R, Flags or DT_CALCRECT);
Brush.Color := Color;//background color of the caption
Font.Color := clRed;//the color of the caption.
DrawText(Handle, PChar(Text), Length(Text), R, Flags);
end;
end
else
inherited; //if the control is not themed then use the original paint method.
end;
end;

RRUZ
- 134,889
- 20
- 356
- 483
-
i cannot find the ThemeControl function i suppose it is this one function ThemeControl(AControl: TControl): Boolean; – Shirish11 Oct 13 '11 at 05:11
-
@ruzz i cannot find the declaration inside the Themes unit(i m using BDS 2006) – Shirish11 Oct 13 '11 at 05:38
-
If that function does not exist in Delphi 2006, then instead of `if ThemeControl(Self) then` write this `if ThemeServices.ThemesEnabled then` – RRUZ Oct 13 '11 at 05:48
-
http://i.stack.imgur.com/q3XM0.jpg this is what i get ,but i want the Background of the Text to be the Same as that of my form Background(which is a image in this case) – Shirish11 Oct 13 '11 at 06:14
-
you must set the `color` property of the `TGroupBox` using the same value of the color of the Form. if that doesn't work you can set the color of the background in this line `Brush.Color := Color;` (please read the comments in the code). – RRUZ Oct 13 '11 at 06:28
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4217/discussion-between-shirish11-and-rruz) – Shirish11 Oct 13 '11 at 06:42