Change tab color and restore to original color

2 posts, 1 answers
  1. joseph_korn
    joseph_korn avatar
    21 posts
    Member since:
    Apr 2007

    Posted 21 Aug 2008 Link to this post

    As per the instructions given in this thread: http://www.telerik.com/community/forums/thread/b311D-mkmhd.aspx I was able to successfully change the backcolor of a tab programmatically.  When I try to reset the tab color back to its original color, it works fine, except that the color stays changed until I hover over the tab, and then it fully returns to normal.

    For example, I have a tab strip with the default blue colored tabs.  I click a button to change one of the tabs to yellow, and it works.  I click another button to change the color back to the original blue color, but the tab still remains yellow.  When I hover my mouse over the yellow tab, it changes to the hover color, and when I hover away from the tab, it returns to its original blue color.

    Here is a sample of my code used to make the tab turn yellow:

                Dim oFillSelector As New ClassSelector("TabFill") 
                Dim oTabFill As FillPrimitive = TryCast(oFillSelector.GetSelectedElements(Me.tsTabs.SelectedTab)(0), FillPrimitive) 
     
                If oTabFill.BackColor <> Color.Yellow Then 
                    oTabFill.BackColor = Color.Yellow 
                    oTabFill.BackColor2 = Color.Yellow 
                    oTabFill.BackColor3 = Color.Yellow 
                    oTabFill.BackColor4 = Color.Yellow 
                End If 


    Here is the code I use to return all tabs to their default color:

    For i as int32 = 0 to Me.tsTabs.Items.Count -1 
            Dim oFillSelector As New ClassSelector("TabFill") 
            Dim oTabFill As FillPrimitive = TryCast(oFillSelector.GetSelectedElements(Me.tsTabs.Items(i))(0), FillPrimitive) 
     
            oTabFill.ResetValue(FillPrimitive.BackColorProperty) 
            oTabFill.ResetValue(FillPrimitive.BackColor2Property) 
            oTabFill.ResetValue(FillPrimitive.BackColor3Property) 
            oTabFill.ResetValue(FillPrimitive.BackColor4Property) 
    Next 

    Please let me know what I am doing wrong, as it is quite annoying to have to hover over all the tabs everytime I want to see which ones are really supposed to have a different backcolor.
  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 22 Aug 2008 Link to this post

    Hi joseph_korn,

    Thank you for this question.

    After you reset the values of all the BackColor properties, you should call the ForceApplyTheme() method:
    Me.tsTabs.RootElement.ForceApplyTheme(); 

    If you have additional questions, feel free to contact me.

    All the best,
    Nikolay
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top