Reputation: 8322
Is it possible to disable (but not entirely remove) a single tab from a TTabSet? How?
It doesn't appear that there's an obvious way to do this.
Upvotes: 3
Views: 2092
Reputation: 2977
In order to change the color of the label to a disabled font color you have to override the drawing of the tabs by changing it's Style property to tsOwnerDraw. Once you've done that you can use the OnDrawTab Event, for example like this :
var
indexOfDisabledTab : Byte = 1;
procedure TForm1.TabSet1DrawTab(Sender: TObject; TabCanvas: TCanvas; R: TRect;
Index: Integer; Selected: Boolean);
var S : String;
begin
if IndexOfDisabledTab = Index
then
TabCanvas.Font.Color := clGray
else
TabCanvas.Font.Color := clBlack;
S := TabSet1.Tabs.Strings[Index];
TabCanvas.TextRect(R, S, [tfVerticalCenter,tfSingleLine]);
end;
To prevent the user from clicking the tab you can use the TTabSet OnChange Event like this:
procedure TForm1.TabSet1Change(Sender: TObject; NewTab: Integer;
var AllowChange: Boolean);
begin
AllowChange := not (NewTab = IndexOfDisabledTab);
end;
Upvotes: 4