[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

Font in tabsheet ?

Hello !

Is it a way to choose differents fonts for the caption of the pagecontrol's tabsheets ?
Thanx
0
nk51
Asked:
nk51
  • 6
  • 5
  • 4
  • +1
1 Solution
 
bruintjeCommented:
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)
0
 
EpsylonCommented:
With the 'as is' TPageControl you can't....
0
 
bruintjeCommented:
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)
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
EpsylonCommented:
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;

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

-Viktor
--Ivanov
0
 
EpsylonCommented:
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;

0
 
nk51Author Commented:
Oups...I'm using Delphi 3.0.
And there's no draw event...

0
 
EpsylonCommented:
And you are telling me this now.....
0
 
nk51Author Commented:
Sorry...
0
 
EpsylonCommented:
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.

0
 
nk51Author Commented:
But PageControl doesn't have a canvas property...
0
 
viktornetCommented:
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
0
 
nk51Author Commented:
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.
0
 
nk51Author Commented:
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;

0
 
viktornetCommented:
I guess your comment about proposing an answer was forward me?!?! if it was not forward me, please reject my answer...

Here are coupld more suggestions..

Instead of this


if Uppercase(PGC_Parametre.ActivePage.Name) =
     Uppercase('TBS_ParametresAssocies')

do this...

if Uppercase(PGC_Parametre.ActivePage.Name) = 'TBS_PARAMETRESASSOCIES'

and this one also...

instead of this...

if Uppercase(PGC_Parametre.ActivePage.Name) =
     Uppercase('TBS_Normes')

do this..

if Uppercase(PGC_Parametre.ActivePage.Name) = 'TBS_NORMES'

also, if you just need to make a simple font you don't need to create a new one...but that depends on you...

for example you could simply do this,..

LCANVAS_Canvas.Font.Color := clblack;
LCANVAS_Canvas.Font.Name := 'Ms Sans Serif;
LCANVAS_Canvas.Font.Size := 8;

Well, I hope this helps.. Let me know if you are still having any problems...

-Viktor
--Ivanov
0
 
nk51Author Commented:
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 !


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

-Viktor
--Ivanov
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now