How To Change The Highlight Color

14 posts, 0 answers
  1. Dian
    Dian avatar
    16 posts
    Member since:
    Oct 2010

    Posted 03 Feb 2011 Link to this post

    Hi All,


    In the picture 1, the radlistbox shows orange highlight color.

    I am wondering how can I change the color like picture 2 as blue highlight.  I tried to changed its themename, but it doesn't work.

    Regards,

    Fendy
      
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 04 Feb 2011 Link to this post

    Hello Dian,

    the very best way to change the highlight colour os to define your own theme. You can find out more about using the Visual Style Builder here.

    However, it is possible to change the highlight colour manually, though it's rather long winded.

    First handle the PopUp Opened event on the RadDropDownList
    this.radDropDownList1.PopupOpened += new EventHandler(radDropDownList1_PopupOpened);

    Handle this event and loop over the visual item, adding a handler to Mouse Enter and Mouse Leave
    void radDropDownList1_PopupOpened(object sender, EventArgs e)
    {
        DefaultListControlStackContainer container = (DefaultListControlStackContainer)this.radDropDownList1.Popup.RootElement.Children[0].Children[1].Children[0];
        foreach (RadListVisualItem item in container.Children)
        {
            item.MouseEnter -= new EventHandler(Item_MouseEnter);
            item.MouseEnter +=new EventHandler(Item_MouseEnter);
            item.MouseLeave -= new EventHandler(item_MouseLeave);
            item.MouseLeave += new EventHandler(item_MouseLeave);
        }
    }

    And change the highlight for these items
    void item_MouseLeave(object sender, EventArgs e)
    {
        ((RadListVisualItem)sender).ResetValue(LightVisualElement.BackColorProperty);
        ((RadListVisualItem)sender).BackColor2 = Color.White;
        ((RadListVisualItem)sender).ResetValue(LightVisualElement.NumberOfColorsProperty);
    }
    void Item_MouseEnter(object sender, EventArgs e)
    {
        ((RadListVisualItem)sender).BackColor = Color.LightBlue;
        ((RadListVisualItem)sender).BackColor2 = Color.Blue;
        ((RadListVisualItem)sender).NumberOfColors = 2;
    }

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 06 Feb 2011 Link to this post

    Hello,

    Did this help? If so please remember to mark as answer.
    If you need futher assistance, please let me know
    thanks
    Richard
  5. Dian
    Dian avatar
    16 posts
    Member since:
    Oct 2010

    Posted 06 Feb 2011 Link to this post

    Hi Richard,

    I am not quite sure whether your codes is helpful or not, because I am using RadListControl  rather than RadDropdownList, also it is created under VB.NET environment, sorry I should mentioned it at first time.

    I am wondering why my RadTreeView has blue highlight when it applied VistaTheme,  and this doesn’t work with my RadListControl.

    Thanks,

    Fendy

  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hello Dian,

    Unfortunately, I don't have the older version of the controls to try this out for you, but I'd advise upgrading to teh latest 2010 Q3 SP1 version as there are many enhancements, fixes and new products in the latest version which I believe would be of benefit to you.

    You can also use Telerik's code converter to change code from/to C#/VB at this link but if you need further help either converting it, or with nything else, just let me know
    Richard
  7. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hi again,

    Apologies, I re-read your post. I will prepare you a sample (if it's different) for the RadListControl. I will get back to you shortly.
    Regards,
    Richard
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hello Dian,

    I've been trying this out, and whilst it is possible, for it to be reliable for all scenarios (different selection modes etc..) I would advise creating a new custom theme as per my above post for the RadListControl using the Visual Style Builder.
    Hope that helps
    Richard
  9. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hi again Dian,

    Whilst I still maintain tha the best way is via VSB, I though the following might be useful for you for use with single selection RadListControl

    In Form Load..
    Me.RadListControl1.SelectionMode = SelectionMode.One
    Dim container As DefaultListControlStackContainer = CType(Me.RadListControl1.RootElement.Children(0).Children(0), DefaultListControlStackContainer)
    For Each item As RadListVisualItem In container.Children
        AddHandler item.MouseEnter, AddressOf Item_MouseEnter
        AddHandler item.MouseLeave, AddressOf Item_MouseLeave
        AddHandler item.MouseDown, AddressOf Item_MouseDown
    Next

    Private Sub Item_MouseEnter(ByVal sender As Object, ByVal e As EventArgs)
        Dim item As RadListVisualItem = CType(sender, RadListVisualItem)
        item.BackColor = Color.LightBlue
        item.BackColor2 = Color.Blue
        item.NumberOfColors = 2
    End Sub
    Private Sub Item_MouseLeave(ByVal sender As Object, ByVal e As EventArgs)
        Dim item As RadListVisualItem = CType(sender, RadListVisualItem)
        If Not item.Selected Then
            item.ResetValue(LightVisualElement.BackColorProperty)
            item.ResetValue(LightVisualElement.NumberOfColorsProperty)
            item.BackColor2 = Color.White
        End If
    End Sub
    Private Sub Item_MouseDown(ByVal sender As Object, ByVal e As EventArgs)
        Dim container As DefaultListControlStackContainer = CType(Me.RadListControl1.RootElement.Children(0).Children(0), DefaultListControlStackContainer)
        For Each item As RadListVisualItem In container.Children
            If Not item Is CType(sender, RadListVisualItem) Then
                item.ResetValue(LightVisualElement.BackColorProperty)
                item.ResetValue(LightVisualElement.NumberOfColorsProperty)
                item.BackColor2 = Color.White
            End If
        Next
    End Sub

    All the best
    Richard
  10. Dian
    Dian avatar
    16 posts
    Member since:
    Oct 2010

    Posted 07 Feb 2011 Link to this post

    Hi Richard,

    Thank you so much for all your help I really appreciate it.

    I tried to use your latest code, but it was generated an error when it fired MouseEnter Event, the error message was saying” Unable to cast object of type 'Telerik.WinControls.UI.RadListControl' to type 'Telerik.WinControls.UI.RadListVisualItem'.”

    As you mentioned, solve this problem is better to use Visual Style Builder, I will try it.

    Cheers,

    Fendy

  11. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 07 Feb 2011 Link to this post

    Hi Fendy,

    Out of interest what version of the controls are you using? If you are on the latest Q3 2010 SP1 version and using a radListControl then the above should work fine. If you're not, which ever method you use, I'd advise to upgrade as there are lots of enhancements, fixes and new controls in the latest version.
    Let me know if you need anything further
    Richard
  12. Dian
    Dian avatar
    16 posts
    Member since:
    Oct 2010

    Posted 07 Feb 2011 Link to this post

    Hi Richard,

    I am using Q3 2010 Version. 

    I have not right to download latest version now, I will get it after some time.

    Anyway, thank you very much.

    Cheers,

    Fendy 

     

  13. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 09 Feb 2011 Link to this post

    Hi guys, 

    Thank you both for writing.

    I want to share that in both Q3 2010 and Q3 2010 SP1 Richard's suggestion works fine. Note that this will work with a single selection only and glitches appear in multiple selection. Like Richard said, the best approach here is to modify the theme with Visual Stile Builder. 

    Additionally, I want to mention that you are able to download the latest version of our controls from your account. Simply navigate to Download Free Trials >> RadControls for WinForms >> Download Free Trial.

    I hope this helps. If you have any further questions, do not hesitate to write back.

    All the best,
    Stefan
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  14. Dylan Lennox
    Dylan Lennox avatar
    3 posts
    Member since:
    Apr 2010

    Posted 03 Jan 2013 Link to this post

    i know this might be the wrong place to ask this but i have a  radbutton that i have changed the back colour and when i click the button an orange border appears and i would like to get rid of that i think it has something to do with focus cause if i click a textbox the orange border goes away
  15. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 08 Jan 2013 Link to this post

    Hello Dylan,

    You are right, this is the wrong place to ask such a question. Please open a new thread in the appropriate section: http://www.telerik.com/community/forums/winforms/buttons.aspx. Also, in the thread, please provide information about how you change the button's color.

    Thank you for the understanding.
     
    Regards,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top
UI for WinForms is Visual Studio 2017 Ready