user1559618 user1559618 - 29 days ago 13
C# Question

Hightlight Listbox item on mouse over event

I am attempting to change a

listview
item's background colour when a mouse hovers over it

I have a mouse hover event, but how can I add a "highlight" effect upon a mouse hovering over the item?

private void pinnedAppsListBox_MouseHover(object sender, EventArgs e)
{

}

Answer

Use this:

private void pinnedAppsListBox_MouseHover(object sender, EventArgs e){

   Point point = pinnedAppsListBox.PointToClient(Cursor.Position);
   int index = pinnedAppsListBox.IndexFromPoint(point);
   if (index < 0) return;
   //Do any action with the item
   pinnedAppsListBox.GetItemRectangle(index).Inflate(1,2);
}
Comments