Can I change the color of TTabSheet tabs

I am running Lazarus 0.9.30.2. I have a TForm on which there is a TPageControl. Inside TPageControl there is a series of TTabSheets (about 30 of them). What I want to do is the color code of the tab, so the first 10 are Red, the next 10 are Blue, and the last 10 are Green. I saw fragments of code on the intranet that change the color of the tab bookmark (including the tab) when you click on them and go to them (to highlight the active tab), but I want them to color them as described above, when they first load tabs.

Is there any way to do this?

enter image description here

+4
source share
1 answer

If you just need to get a slightly complicated solution that works only on Windows with themes disabled , try the following:

Uncheck the Use manifest file to enable themes (Windows only) option in the Project / Project Options ... project settings dialog box and paste the following code into your block using the page control. It uses an inserted class, so it will only work in units where you insert this code.

 uses ComCtrls, Windows, LCLType; type TPageControl = class(ComCtrls.TPageControl) private procedure CNDrawItem(var Message: TWMDrawItem); message WM_DRAWITEM; protected procedure CreateParams(var Params: TCreateParams); override; end; implementation procedure TPageControl.CreateParams(var Params: TCreateParams); begin inherited CreateParams(Params); with Params do begin if not (csDesigning in ComponentState) then Style := Style or TCS_OWNERDRAWFIXED; end; end; procedure TPageControl.CNDrawItem(var Message: TWMDrawItem); var BrushHandle: HBRUSH; BrushColor: COLORREF; begin with Message.DrawItemStruct^ do begin case itemID of 0: BrushColor := RGB(235, 24, 33); 1: BrushColor := RGB(247, 200, 34); 2: BrushColor := RGB(178, 229, 26); else BrushColor := ColorToRGB(clBtnFace); end; BrushHandle := CreateSolidBrush(BrushColor); FillRect(hDC, rcItem, BrushHandle); SetBkMode(hDC, TRANSPARENT); DrawTextEx(hDC, PChar(Page[itemID].Caption), -1, rcItem, DT_CENTER or DT_VCENTER or DT_SINGLELINE, nil); end; Message.Result := 1; end; 

This is how it looks (ugly :)

enter image description here

+4
source

Source: https://habr.com/ru/post/1397181/


All Articles