Board index » delphi » TPageControl, TTabSheet help requested

TPageControl, TTabSheet help requested

Does anyone have an example of setting the text color of the caption(or a
rect around the text) on a TTabSheet at runtime?
 

Re:TPageControl, TTabSheet help requested


That does not change the caption at the top. It only changes items
actually on the tabsheet. I believe the rectangle with the caption
belongs to the pagecontrol.

Johno

Quote
felipe wrote in message <01bdc0b0$f9871ac0$5b72c80a@mozart>...
>Try TabSheet1.Font.Color:= <the requested color>

>John Owen <jo...@tmscorp.com> wrote in article
><6qaf4p$c...@forums.borland.com>...
>> Does anyone have an example of setting the text color of the caption(or a
>> rect around the text) on a TTabSheet at runtime?

Re:TPageControl, TTabSheet help requested


Try TabSheet1.Font.Color:= <the requested color>

John Owen <jo...@tmscorp.com> wrote in article
<6qaf4p$c...@forums.borland.com>...

Quote
> Does anyone have an example of setting the text color of the caption(or a
> rect around the text) on a TTabSheet at runtime?

Re:TPageControl, TTabSheet help requested


Quote
John Owen wrote in message <6qaf4p$c...@forums.borland.com>...
>Does anyone have an example of setting the text color of the caption(or a
>rect around the text) on a TTabSheet at runtime?

John,

You're sort of out of luck in D3 because the standard TPageControl does not
provide for OwnerDraw. You could get a 3rd party control perhaps, or you
could create your own control from TPageControl and set TCS_OWNERDRAWFIXED
in the style and respond to WM_DRAWITEM messages. See 'Tab Controls' in
WIN32.HLP for more details.

However, D4 does provide for OwnerDraw  and below is a code snippet that I
use to show different colored tabs and texts. Just set OwnerDraw to true on
the TPageControl to engage and set HotTrack to false for best results.

Dave H.
--------------------------------------------------------------------
procedure TfrmMain.tabMainDrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  wrkRect:TRect;
  wrkTop:integer;
begin
  with tabMain.Canvas do begin
   wrkRect:=Rect;             // Rect is constant, see header
   if not Active then
    begin
     Inc(wrkRect.Bottom,2);   // Make it a little bigger for style
     wrkTop:=wrkRect.Top+3;
     Font.Color:=clSilver;
    end
   else
    begin
     wrkTop:=wrkRect.Top+4;
     Font.Color:=clWhite;
    end;
   case TabIndex of
    0: Brush.Color:=clNavy;   // tab 1
    1: Brush.Color:=clMaroon; // tab 2
    else                      // tab ...
     begin
      Brush.Color:=clBtnFace;
      Font.Color:=tabMain.Font.Color;
     end;
   end;
   FillRect(wrkRect);
   Brush.Style:=bsClear;
   TextOut(Rect.Left+6,wrkTop,tabMain.Pages[TabIndex].Caption);
  end;
end;
--------------------------------------------------------------------

Other Threads