nk51
asked on
Font in tabsheet ?
Hello !
Is it a way to choose differents fonts for the caption of the pagecontrol's tabsheets ?
Thanx
Is it a way to choose differents fonts for the caption of the pagecontrol's tabsheets ?
Thanx
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)
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(Rec t.Left + Font.Size, Rect.Top + 2, 'MyTab');
end;
Had to set the OwnerDraw property to true.
procedure TForm1.PageControl1DrawTab
TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
case TabIndex of
0: Font.Color := clRed;
1: Font.Color := clBlue;
end;
Control.Canvas.TextOut(Rec
end;
You can try Epsylon's method with the API CreateFont() to get a nice font...
-Viktor
--Ivanov
-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(Re ct);
Control.Canvas.TextOut(Rec t.Left + Font.Size, Rect.Top + 2, 'MyTab');
end;
PageControl1.OwnerDraw := True;
procedure TForm1.PageControl1DrawTab
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(Re
Control.Canvas.TextOut(Rec
end;
ASKER
Oups...I'm using Delphi 3.0.
And there's no draw event...
And there's no draw event...
And you are telling me this now.....
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.
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
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
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.
It works !!!
It's excellent.
Post an "answer" and I give you the 50 points.
ASKER
For an example, here is my code :
procedure TFRM_DetailParametres.Affi chageTabSh eets;
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_Fon te);
LCANVAS_Canvas.Brush.Color := clBtnFace;
LCANVAS_Canvas.Handle := GetDC(PGC_Parametre.Handle );
if Uppercase(PGC_Parametre.Ac tivePage.N ame) = Uppercase('TBS_ParametresA ssocies')
then
LCANVAS_Canvas.TextOut(320 , 3, ' Paramètres associés ')
else
LCANVAS_Canvas.TextOut(320 , 5, ' Paramètres associés ')
;
if Uppercase(PGC_Parametre.Ac tivePage.N ame) = 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;
procedure TFRM_DetailParametres.Affi
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
LCANVAS_Canvas.Brush.Color
LCANVAS_Canvas.Handle := GetDC(PGC_Parametre.Handle
if Uppercase(PGC_Parametre.Ac
then
LCANVAS_Canvas.TextOut(320
else
LCANVAS_Canvas.TextOut(320
;
if Uppercase(PGC_Parametre.Ac
then
LCANVAS_Canvas.TextOut(450
else
LCANVAS_Canvas.TextOut(450
;
finally
LCANVAS_Canvas.Free;
LFONT_Fonte.free;
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 !
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
-Viktor
--Ivanov
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)