Solved

Font in tabsheet ?

Posted on 1999-01-27
17
612 Views
Last Modified: 2013-12-02
Hello !

Is it a way to choose differents fonts for the caption of the pagecontrol's tabsheets ?
Thanx
0
Comment
Question by:nk51
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
  • +1
17 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 1363549
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
 
LVL 13

Expert Comment

by:Epsylon
ID: 1363550
With the 'as is' TPageControl you can't....
0
 
LVL 44

Expert Comment

by:bruintje
ID: 1363551
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Epsylon
ID: 1363552
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1363553
You can try Epsylon's method with the API CreateFont() to get a nice font...

-Viktor
--Ivanov
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1363554
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
 

Author Comment

by:nk51
ID: 1363555
Oups...I'm using Delphi 3.0.
And there's no draw event...

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1363556
And you are telling me this now.....
0
 

Author Comment

by:nk51
ID: 1363557
Sorry...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1363558
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
 

Author Comment

by:nk51
ID: 1363559
But PageControl doesn't have a canvas property...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1363560
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
 

Author Comment

by:nk51
ID: 1363561
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
 

Author Comment

by:nk51
ID: 1363562
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
 
LVL 10

Accepted Solution

by:
viktornet earned 50 total points
ID: 1363563
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
 

Author Comment

by:nk51
ID: 1363564
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1363565
No problem.. let me know if you are still having problems with this thiny, k?

-Viktor
--Ivanov
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question