I have tabcontrol component on my form. After I put XPManifest, its color became white, I want to change it, but couldn't find color property. And I don't want to remove XPManifest as well. Is there any way to solve this issue?
+3
A:
To change the color of a TTabControl must put the OwnerDraw property to true false and write your own code to draw the tabs and the background in the OnDrawTab Event.
see this example.
procedure TForm38.TabControl1DrawTab(Control: TCustomTabControl; TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
y : Integer;
x : Integer;
aRect: TRect;
begin
if Active then
begin
//Fill the tab rect
Control.Canvas.Brush.Color := clWebGainsboro;
Control.Canvas.FillRect(Rect);
//Fill the background
aRect.Left:=1;
aRect.Right:=Control.Width-1;
aRect.Bottom:=Control.Height-1;
aRect.Top:=Rect.Bottom+1;
Control.Canvas.FillRect(aRect);
end
else
begin
//Fill the tab rect
Control.Canvas.Brush.Color := clBtnFace;
Control.Canvas.FillRect(Rect);
end;
y := Rect.Top + ((Rect.Bottom - Rect.Top - Control.Canvas.TextHeight(TTabControl(Control).Tabs[TabIndex])) div 2) + 1;
x := Rect.Left + ((Rect.Right - Rect.Left - Control.Canvas.TextWidth (TTabControl(Control).Tabs[TabIndex])) div 2) + 1;
//draw the tab title
Control.Canvas.TextOut(x,y,TTabControl(Control).Tabs[TabIndex]);
end;
RRUZ
2009-11-28 13:41:26
I have just noticed interesting thing: The OwnerDraw property actually was False, probably that's why it is white. When I put it to True, the background color becomes correct, but the tab captions become invisible O_o.. Can you comment on that?
Tofig Hasanov
2009-11-30 07:41:44
This procedure works fine, thanks. One thing I should notice also is that it only works when OwnerDraw it TRUE, not FALSE. When OwnerDraw is false, OnDrawTab is not called.
Tofig Hasanov
2009-11-30 07:49:15
@Tofig: Correct, OwnerDraw instructs the control that it needs to call OnDrawTab to draw itself.
skamradt
2009-11-30 17:53:40
Corrected, Ownerdraw should be true.
RRUZ
2009-11-30 23:45:58