juank
asked on
TTabSheets - May I Change the tab color?
Hi folks:
Here a goes a couple of little questions related with TTabSheets.
How could I do in D3 to:
1) Assign a color to the Tab of a TTabSheet
2) Make that color change if the TabSheet is active or not
Thank you and regards
JuanK
Here a goes a couple of little questions related with TTabSheets.
How could I do in D3 to:
1) Assign a color to the Tab of a TTabSheet
2) Make that color change if the TabSheet is active or not
Thank you and regards
JuanK
well, my version,
sorry to say, f68, your painting routine paints a bit ugly,
and will left a small blue line on the canvas
//property OwnerDraw must be set to true
procedure TForm1.PageControl1DrawTab (Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var ARect : TRect;
begin
ARect := Rect;
//clear complete
control.Canvas.brush.Color := clBtnFace;
control.Canvas.FillRect(AR ect);
InflateRect(ARect,-2,-2);
//decide the color
if active then
control.Canvas.brush.Color := clRed
else
control.Canvas.brush.Color := clBtnFace;
//paint the tab
control.Canvas.FillRect(AR ect);
Control.Canvas.TextOut(ARe ct.Left+2, ARect.top+ 2,
TPageControl(Control).Page s[TabIndex ].Caption) ;
end;
meikl ;-)
sorry to say, f68, your painting routine paints a bit ugly,
and will left a small blue line on the canvas
//property OwnerDraw must be set to true
procedure TForm1.PageControl1DrawTab
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var ARect : TRect;
begin
ARect := Rect;
//clear complete
control.Canvas.brush.Color
control.Canvas.FillRect(AR
InflateRect(ARect,-2,-2);
//decide the color
if active then
control.Canvas.brush.Color
else
control.Canvas.brush.Color
//paint the tab
control.Canvas.FillRect(AR
Control.Canvas.TextOut(ARe
TPageControl(Control).Page
end;
meikl ;-)
well, this problem happens to me too,
if i change also the fontstyle as f68 ([fsBold],[])
instead of
Control.Canvas.TextOut(ARe ct.Left+2, ARect.top+ 2,
TPageControl(Control).Page s[TabIndex ].Caption) ;
use
control.Canvas.TextRect(AR ect,ARect. Left+2,ARe ct.top+1,
TPageControl(Control).Page s[TabIndex ].Caption) ;
meikl ;-)
if i change also the fontstyle as f68 ([fsBold],[])
instead of
Control.Canvas.TextOut(ARe
TPageControl(Control).Page
use
control.Canvas.TextRect(AR
TPageControl(Control).Page
meikl ;-)
--> if i change also the fontstyle as f68 ([fsBold],[])
glad about it :)))) BTW in fact your method should be better...
F68 ;-)
glad about it :)))) BTW in fact your method should be better...
F68 ;-)
ASKER
Hi folks.
Thank you for your answers, but where do I find the property OwnerDraw?? And the DrawTab Event ??
Let me remember you all that this question is related with Delphi 3, and I couldn't find them, even in the help :-(
Best regards,
Juank
Thank you for your answers, but where do I find the property OwnerDraw?? And the DrawTab Event ??
Let me remember you all that this question is related with Delphi 3, and I couldn't find them, even in the help :-(
Best regards,
Juank
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok.
Anyway, don't worry as I convinced the client that the colored tabs were "annoying"
Rgds.
Juank
Anyway, don't worry as I convinced the client that the colored tabs were "annoying"
Rgds.
Juank
in DrawTab this
procedure TForm1.PageControl1DrawTab
TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
with control.Canvas do begin
if active then begin
Font.Style := [fsBold];
brush.Color := clblue;
end else begin
font.Style := [];
brush.Color := clred;
end;
TextOut(Rect.Left + Font.Size,
Rect.Top + 2,PageControl1.Pages[tabin
end;
end;