Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Highlighting items in listbox when mouse moves over them

Highlighting items in listbox when mouse moves over them

Scheduled Pinned Locked Moved C#
graphicsquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gary Strunk
    wrote on last edited by
    #1

    In a comboBox as you move the mouse across the list of items, the item under the mouse is highlighted (without clicking on it). How do you make a list box work the same way? Currently I display a different picture for each item in the listbox as the mouse moves over it, but without it higlighting as I move over it, it is sometimes difficult to tell which item I am drawing for. I have search the internet and several books for this but have not found anything related to this topic. Gary

    N 1 Reply Last reply
    0
    • G Gary Strunk

      In a comboBox as you move the mouse across the list of items, the item under the mouse is highlighted (without clicking on it). How do you make a list box work the same way? Currently I display a different picture for each item in the listbox as the mouse moves over it, but without it higlighting as I move over it, it is sometimes difficult to tell which item I am drawing for. I have search the internet and several books for this but have not found anything related to this topic. Gary

      N Offline
      N Offline
      Nuri Ismail
      wrote on last edited by
      #2

      The simplest way to achieve this is to get the index of the item that is below the mouse using the IndexFromPoint and select this item:

      private void listTest_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
      {
      // Get the index of the item below the mouse pointer
      int index = listTest.IndexFromPoint(e.X, e.Y);
      listTest.SelectedIndex = index;
      }

      Regards Nuri

      G 1 Reply Last reply
      0
      • N Nuri Ismail

        The simplest way to achieve this is to get the index of the item that is below the mouse using the IndexFromPoint and select this item:

        private void listTest_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
        // Get the index of the item below the mouse pointer
        int index = listTest.IndexFromPoint(e.X, e.Y);
        listTest.SelectedIndex = index;
        }

        Regards Nuri

        G Offline
        G Offline
        Gary Strunk
        wrote on last edited by
        #3

        I knew there had to be a simple way to do it, and after seeing this I feel embrassed that I didn't think to try that myself. Thank you very much. Gary

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups