Search code examples
delphifiremonkey

How to make a tab invisible, but not the sheet that would show when the tab is selected? - Delphi FireMonkey


I want to be able to open tabA from a button on tabB. But I don't want the user to be able to open tabA, apart from using that button. However if you set the TabA.Visible := False it sets the tab and the tab sheet as not visible. Is there any way around this?

My idea would be to cover tabB with a blank white image when I need tabA showing, and when I need tabB showing just hide all the tabA controls. Would this be the best thing to do for this issue?


Solution

  • I want to be able to open tabA from a button on tabB. But I don't want the user to be able to open tabA, apart from using that button. However if you set the TabA.Visible := False it sets the tab and the tab sheet as not visible. Is there any way around this?

    You can hide the tabs (while keeping the sheets visible) by setting property TabControl1.TabPosition = None. Note! This setting makes all tabs invisible.

    So no, you don't need any images or anything else to cover either sheet.

    Moving between the tab sheets can then be done in code in one of three ways:

    • setting TabControl1.ActiveTab to a TTabItem
    • setting TabControl1.TabIndex to the index of a tab sheet (index is zero-based)
    • calling TabControl1.Next/Previous to move to the following/previous tab sheet

    Example code

    // Button on first tabsheet
    procedure TForm5.Button1Click(Sender: TObject);
    begin
    //  TabControl1.ActiveTab := TabItem2; // Immediate transition
    //  TabControl1.TabIndex := 1;  // Immediate transition
      TabControl1.Next;  // Animated transition
    end;
    
    // Button on second tabsheet
    procedure TForm5.Button2Click(Sender: TObject);
    begin
    //  TabControl1.ActiveTab := TabItem1; // Immediate transition
    //  TabControl1.TabIndex := 0;  // Immediate transition
      TabControl1.Previous;  // Animated transition
    end;