Make Ribbontabs invisible from code

May 9, 2016 at 4:59 PM
I want to make ribbontabs appear dependent on what the user is doing via code. ie I have 5 tabs designed but only one tab is visible to the user at any one time.

I have changed the active, visible and selected properties to be visible and have added the following code to a button event:
  private void button4_Click(object sender, EventArgs e)
      if (ribbonTab2.Visible)
          ribbonTab2.Visible = false;
          ribbonTab1.Visible = true;
          ribbonTab1.Selected = true;
          ribbonTab1.Pressed = true;
          ribbonTab1.Active = true;
          ribbonTab2.Visible = true;
          ribbonTab2.Selected = true;
          ribbonTab2.Pressed = true;
          ribbonTab1.Visible = false;
          ribbonTab1.Active  = true;
The problem I am having is that although the tabs are showing correctly the controls handling is still processing the previous tabs controls and this can only be corrected by clicking the tab. Due to my limited knowledge of c# I need some help in understanding how I can mimic the TabHitTest code in ribbon.cs when I am changing the visible property :
    /// <summary>
    /// Hittest on tab
    /// </summary>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns>true if a tab has been clicked</returns>
    internal bool TabHitTest(int x, int y)
        //if (Rectangle.FromLTRB(Right - 10, Bottom - 10, Right, Bottom).Contains(x, y))
        //   MessageBox.Show(cr);

        //look for mouse on tabs
        foreach (RibbonTab tab in Tabs)
            if (tab.TabBounds.Contains(x, y))
                ActiveTab = tab;
                Expanded = true;

                return true;

        return false;
Many thanks