Solved

Font in tabsheet ?

Posted on 1999-01-27
17
602 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
  • 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now