Controlling tab Colors

4 posts, 0 answers
  1. bobebs
    bobebs avatar
    7 posts
    Member since:
    May 2007

    Posted 06 Jun 2007 Link to this post

    How do I programmically change the color of a tab(s) on the tabstrip depending certain conditions.  I tried changing both the foregcolor and backcolor properties but it does not work.  Do I have to change the "theme"?  if so how?
  2. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 08 Jun 2007 Link to this post

    Hello Bob,

    You could use the ClassSelector class to select the fill of the TabItem and then modify the BackColor 
    properties of that TabItem. The following code demonstrates how to change the backColor of an instance of TabItem.
       
        ClassSelector fillSelector = new ClassSelector("TabFill");
        FillPrimitive tabFill = fillSelector.GetSelectedElements(this.tabItem2)[0] as FillPrimitive;
        tabFill.BackColor = Color.Red;
        tabFill.BackColor2 = Color.Red;
        tabFill.BackColor3 = Color.Red;
        tabFill.BackColor4 = Color.Red;

    The next block demonstrates how to reset the values of the BackColor properties.

         ClassSelector fillSelector = new ClassSelector("TabFill");
         FillPrimitive tabFill = fillSelector.GetSelectedElements(this.tabItem2)[0] as FillPrimitive;
          tabFill.ResetValue(FillPrimitive.BackColorProperty);
          tabFill.ResetValue(FillPrimitive.BackColor2Property);
          tabFill.ResetValue(FillPrimitive.BackColor3Property);
          tabFill.ResetValue(FillPrimitive.BackColor4Property);


    I hope this helps.


    Kind regards,
    Ray
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. BillFugina
    BillFugina avatar
    3 posts
    Member since:
    Sep 2006

    Posted 15 Dec 2008 Link to this post

    How would I do the same thing for the various states of the tabs?
  5. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 18 Dec 2008 Link to this post

    Hello BillFugina,

    I think the only possible approach here is to handle the Mouse events of the control and apply different colors in the different states. However the best approach is to build your own custom theme using our tool for building themes - VisualStyleBuilder. You can find more information about it here:
    http://www.telerik.com/help/winforms/themes_overview.html


    Greetings,
    Boyko Markov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top