change style on onmouseover for radlistbox

5 posts, 1 answers
  1. vighnesh
    vighnesh avatar
    7 posts
    Member since:
    Feb 2009

    Posted 17 Feb 2009 Link to this post

    Hello,

    How do we change background color of a radlistitem in radlistbox when mouse is over that specific item programatically?
    Currently we can see background color getting changed only when item is selected. Thank you.
  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 17 Feb 2009 Link to this post

    Hi vighnesh,

    Thank you for the question.

    In order to change the colors of a RadListBoxItem on mouse hover, please subscribe to its MouseEnter and MouseLeave events:
    public partial class Form1 : Form  
        {  
            public Form1()  
            {  
                InitializeComponent();  
     
                for (int i = 0; i < this.radListBox1.Items.Count; i++)  
                {  
                    ((RadListBoxItem)this.radListBox1.Items[i]).MouseLeave += new EventHandler(Form1_MouseLeave);  
                    ((RadListBoxItem)this.radListBox1.Items[i]).MouseEnter += new EventHandler(Form1_MouseEnter);  
                }  
            }  
     
            void Form1_MouseEnter(object sender, EventArgs e)  
            {  
                RadListBoxItem item = sender as RadListBoxItem;  
                (((FillPrimitive)item.Children[0])).BackColor = Color.Orange;  
                (((FillPrimitive)item.Children[0])).BackColor2 = Color.Red;  
                (((FillPrimitive)item.Children[0])).BackColor3 = Color.Red;  
                (((FillPrimitive)item.Children[0])).BackColor4 = Color.Red;  
            }  
     
            void Form1_MouseLeave(object sender, EventArgs e)  
            {  
                RadListBoxItem item = sender as RadListBoxItem;  
                (((FillPrimitive)item.Children[0])).BackColor = Color.White;  
                (((FillPrimitive)item.Children[0])).BackColor2 = Color.White;  
                (((FillPrimitive)item.Children[0])).BackColor3 = Color.White;  
                (((FillPrimitive)item.Children[0])).BackColor4 = Color.White;  
            }  
        } 

    I hope this helps. If you have additional questions, feel free to contact me.

    Kind regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. vighnesh
    vighnesh avatar
    7 posts
    Member since:
    Feb 2009

    Posted 18 Feb 2009 Link to this post

    Thank you. that worked for me.
  5. Amir
    Amir avatar
    3 posts
    Member since:
    Jul 2012

    Posted 19 Jun 2015 in reply to Nikolay Link to this post

    I do have the latest version of DevCraft but I cannot find the right lib for the FillPrimitive.

    I am not seeing any WinControls.Primitives to add to VS resources!

  6. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 23 Jun 2015 Link to this post

    Hello Amir,

    Thank you for writing.

    The FillPrimitive class is located in the Telerik.WinControls.dll assembly, so in order to access them you would need to reference it.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready