This is a migrated thread and some comments may be shown as answers.

How To Change The Highlight Color

13 Answers 775 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
Dian
Top achievements
Rank 1
Dian asked on 04 Feb 2011, 12:04 AM
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
  

13 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 04 Feb 2011, 01:23 PM
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
0
Richard Slade
Top achievements
Rank 2
answered on 06 Feb 2011, 11:20 PM
Hello,

Did this help? If so please remember to mark as answer.
If you need futher assistance, please let me know
thanks
Richard
0
Dian
Top achievements
Rank 1
answered on 06 Feb 2011, 11:42 PM

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

0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 10:45 AM
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
0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 11:13 AM
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
0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 11:47 AM
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
0
Richard Slade
Top achievements
Rank 2
answered on 07 Feb 2011, 03:03 PM
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
0
Dian
Top achievements
Rank 1
answered on 07 Feb 2011, 08:32 PM

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

0
Richard Slade
Top achievements
Rank 2
answered on 08 Feb 2011, 12:32 AM
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
0
Dian
Top achievements
Rank 1
answered on 08 Feb 2011, 01:41 AM
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 

 

0
Stefan
Telerik team
answered on 09 Feb 2011, 11:05 AM
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.
0
Dylan Lennox
Top achievements
Rank 1
answered on 03 Jan 2013, 08:00 PM
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
0
Stefan
Telerik team
answered on 08 Jan 2013, 01:52 PM
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.
Tags
ListControl
Asked by
Dian
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Dian
Top achievements
Rank 1
Stefan
Telerik team
Dylan Lennox
Top achievements
Rank 1
Share this question
or