Link to home
Start Free TrialLog in
Avatar of nk51
nk51

asked on

Font in tabsheet ?

Hello !

Is it a way to choose differents fonts for the caption of the pagecontrol's tabsheets ?
Thanx
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hi nk51,

Good question, the pagecontrol owns the captions, and so the font properties of the pagecontrol will be the same for all sheets you put on it. The sheets themselves have their own font properties but they don't set their captions.

Curious for an answer....
:O)
Avatar of Epsylon
Epsylon

With the 'as is' TPageControl you can't....
So what's the suggestion?
Inherit your own ccPageControl form TPagecontrol and overriding the published properties caption and font, and probably creating a caption + font for each new page?

:O)
Maybe, I tried once to use the OnDrawTab event but there seems to be some bug in it. (Delphi 4)


Had to set the OwnerDraw property to true.

procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
  case TabIndex of
    0: Font.Color := clRed;
    1: Font.Color := clBlue;
  end;
  Control.Canvas.TextOut(Rect.Left + Font.Size, Rect.Top + 2, 'MyTab');
end;

You can try Epsylon's method with the API CreateFont() to get a nice font...

-Viktor
--Ivanov
What on earth was I thinking? Got it solved! At least for Delphi 4.

PageControl1.OwnerDraw := True;

procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
  case TabIndex of
    0: Control.Canvas.Font.Name := Screen.Fonts[3];
    1: Control.Canvas.Font.Color := clBlue;
  end;
  Control.Canvas.FillRect(Rect);
  Control.Canvas.TextOut(Rect.Left + Font.Size, Rect.Top + 2, 'MyTab');
end;

Avatar of nk51

ASKER

Oups...I'm using Delphi 3.0.
And there's no draw event...

And you are telling me this now.....
Avatar of nk51

ASKER

Sorry...
The only way in Delphi 3 is to intercept the OnChange Event and draw on the pagecontrol's canvas directly with fillrect and textout. You will have to find out where the tabs are on the canvas. The only usable info for that is the fontsize and the length of the captions of the tabs.

Avatar of nk51

ASKER

But PageControl doesn't have a canvas property...
hello nk51...

actually you don't need pagecontrol's canvas since the TCanvas object is simply holds the DC (Device Context) of a control.. In order to get the DC of a control you should do something like this.///

var
  DC : hDC;
begin
  DC := GetDC(DC, PageControl.Handle);
  TextOut(DC, 100, 100, 'whatever', 9);
  ReleaseDC(DC, PageControl.Handle);
end;

I hope this helps...

you can also do this if you want to use the canvas class.....

var
  can : TCanvas;
begin
  can := TCanvas.Create;
  try
    can.Handle := GetDC(PageControl.Handle);
    can.TextOut(100, 100, 'whatever');
    can.FillRect(can.ClipRect);
  finally
    can.Free;
  end;
end;

let me know if you need more help with this..

-Viktor
--Ivanov
Avatar of nk51

ASKER

The both answer you proposed are good but the second are best because I need to control the font of the canvas.
It works !!!
It's excellent.
Post an "answer" and I give you the 50 points.
Avatar of nk51

ASKER

For an example, here is my code :

procedure TFRM_DetailParametres.AffichageTabSheets;
var
  LCANVAS_Canvas : TCanvas;
  LFONT_Fonte    : TFont;
begin

  LCANVAS_Canvas := TCanvas.Create;
  LFONT_Fonte    := TFont.Create;
  try
    LFONT_Fonte.Color := clblack;
    LFONT_Fonte.Name := 'Ms Sans Serif';
    LFONT_Fonte.Size := 8;
    LCANVAS_Canvas.Font.Assign(LFONT_Fonte);
    LCANVAS_Canvas.Brush.Color := clBtnFace;
    LCANVAS_Canvas.Handle := GetDC(PGC_Parametre.Handle);

    if Uppercase(PGC_Parametre.ActivePage.Name) = Uppercase('TBS_ParametresAssocies')
    then
      LCANVAS_Canvas.TextOut(320, 3, '   Paramètres associés    ')
    else
      LCANVAS_Canvas.TextOut(320, 5, '   Paramètres associés    ')
    ;

    if Uppercase(PGC_Parametre.ActivePage.Name) = Uppercase('TBS_Normes')
    then
      LCANVAS_Canvas.TextOut(450, 3, ' Normes  ')
    else
      LCANVAS_Canvas.TextOut(450, 5, ' Normes  ')
    ;

  finally
    LCANVAS_Canvas.Free;
    LFONT_Fonte.free;

  end;

end;

ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nk51

ASKER

Sorry, in my latest comment, I forgot to write your name Viktornet.
The 50 points are for you. And thanx for your latest advices. You're right !


No problem.. let me know if you are still having problems with this thiny, k?

-Viktor
--Ivanov