Recent

Author Topic: [SOLVED] Bold active tab  (Read 2136 times)

SaraT

  • Full Member
  • ***
  • Posts: 139
  • A little student
[SOLVED] Bold active tab
« on: April 09, 2023, 04:24:28 pm »
Hi guys

Is there a way to bold the caption active tab in TPageControl?
Any help would be appreciated.

Take a look at the sample at attached image.
Thanks a lot!
« Last Edit: April 10, 2023, 02:46:35 am by SaraT »

jamie

  • Hero Member
  • *****
  • Posts: 7705
Re: Bold active tab
« Reply #1 on: April 09, 2023, 05:47:20 pm »
Each tab has a OnShow and OnHide. Implement a single event for each and send all the created tabs to that one event.

Use the SENDER to identify the correct tab.

while in there, you can change the font settings for that tab.
The only true wisdom is knowing you know nothing

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Bold active tab
« Reply #2 on: April 09, 2023, 05:57:30 pm »
@jamie

This won't work, at least not on Qt. It will change the font for the TabSheet, i.e. all controls on it that use ParentFont=True will become bold. But the Caption of that TabSheet remains non-bold.

Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 7705
Re: Bold active tab
« Reply #3 on: April 09, 2023, 05:59:56 pm »
ah, ok...

stupid  me >:(
The only true wisdom is knowing you know nothing

SaraT

  • Full Member
  • ***
  • Posts: 139
  • A little student
Re: Bold active tab
« Reply #4 on: April 09, 2023, 07:11:24 pm »
Thanks @jamie @Blaazen

I tried this onShow tab but ALL tabs are bold:
Code: Pascal  [Select][+][-]
  1. Font.Style := [fsBold]

This does nothing onShow:
Code: Pascal  [Select][+][-]
  1. TTabSheet(Sender).Font.Style := [fsBold]

Any code to bold only active tab? Thanks again...

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Bold active tab
« Reply #5 on: April 09, 2023, 09:20:00 pm »
For what target system?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

SaraT

  • Full Member
  • ***
  • Posts: 139
  • A little student
Re: Bold active tab
« Reply #6 on: April 09, 2023, 09:37:52 pm »
For what target system?

Windows 11, Lazarus v2.2.6

jamie

  • Hero Member
  • *****
  • Posts: 7705
Re: Bold active tab
« Reply #7 on: April 09, 2023, 11:57:39 pm »
Look at this test project.

It uses a TPanel as an overlay control over the tab that is currently selected.

This allows you to color the background, set the font for the currently selected tab.

I only did a simple test app, you will need to reform it from there.
The TabRect gives -(?) sizes depending on which side you are on.

and I didn't do any multi_Row test either but you can look at what I did.

 Using a Tpanel overly that fits the same size as the tab allows you to implement mouse events on that tab too!.
The only true wisdom is knowing you know nothing

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Bold active tab
« Reply #8 on: April 10, 2023, 12:07:16 am »
Maybe this brings you to a satisfied result? (Windows only)
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes , SysUtils , Forms , Controls , Graphics , Dialogs , ComCtrls , Windows , LCLType;
  9.  
  10. type
  11.   TPageControl = class(ComCtrls.TPageControl)
  12.   private
  13.     procedure CNDrawItem(var Message: TWMDrawItem); message WM_DRAWITEM;
  14.   protected
  15.     procedure CreateParams(var Params: TCreateParams); override;
  16.   end;
  17.  
  18.  
  19. type
  20.  
  21.   { TForm1 }
  22.  
  23.   TForm1 = class(TForm)
  24.     PageControl1: TPageControl;
  25.     TabSheet1: TTabSheet;
  26.     TabSheet2: TTabSheet;
  27.     TabSheet3: TTabSheet;
  28.   private
  29.  
  30.   public
  31.  
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. implementation
  38.  
  39. {$R *.lfm}
  40.  
  41. procedure TPageControl.CreateParams(var Params: TCreateParams);
  42. begin
  43.   inherited CreateParams(Params);
  44.   with Params do
  45.   begin
  46.     if not (csDesigning in ComponentState) then
  47.       Style := Style or TCS_OWNERDRAWFIXED;
  48.   end;
  49. end;
  50.  
  51. procedure TPageControl.CNDrawItem(var Message: TWMDrawItem);
  52. var
  53.   FontHandle: HFONT;
  54.   FontColor: COLORREF;
  55.   FontObject: TLogFont;
  56.   BrushColor: COLORREF;
  57.   BrushHandle: HBRUSH;
  58. begin
  59.   with Message.DrawItemStruct^ do
  60.   begin
  61.     BrushColor := ColorToRGB(clBtnFace);
  62.     GetObject(Font.Handle, SizeOf(FontObject), @FontObject);
  63.     if itemID <> Self.TabIndex then
  64.       begin
  65.         FontObject.lfWeight := FW_BOLD;
  66.         FontObject.lfItalic := 0;
  67.       end
  68.       else
  69.       begin
  70.         FontObject.lfWeight := FW_NORMAL;
  71.         FontObject.lfItalic := 1;
  72.       end;
  73.     FontColor := clBlack;
  74.     BrushHandle := CreateSolidBrush(BrushColor);
  75.     FillRect(hDC, rcItem, BrushHandle);
  76.     FontHandle := CreateFontIndirect(FontObject);
  77.     try
  78.       SelectObject(hDC, FontHandle);
  79.       SetTextColor(hDC, FontColor);
  80.       SetBkMode(hDC, TRANSPARENT);
  81.       DrawTextEx(hDC, PChar(Page[itemID].Caption), -1, rcItem, DT_CENTER or
  82.         DT_VCENTER or DT_SINGLELINE, nil);
  83.     finally
  84.       DeleteObject(FontHandle);
  85.     end;
  86.   end;
  87.   Message.Result := 1;
  88. end;
  89.  
  90. end.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

SaraT

  • Full Member
  • ***
  • Posts: 139
  • A little student
Re: [SOLVED] Bold active tab
« Reply #9 on: April 10, 2023, 02:46:56 am »
@jamie @KodeZwerg

Thanks a lot, both examples worked perfectly.
Best regards!

Paolo

  • Hero Member
  • *****
  • Posts: 713
Re: [SOLVED] Bold active tab
« Reply #10 on: April 10, 2023, 10:55:00 am »

 

TinyPortal © 2005-2018