Results 1 to 3 of 3

Thread: [RESOLVED] MouseHover event for Multiple Controls?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Resolved [RESOLVED] MouseHover event for Multiple Controls?

    Hi guys, my problem is this. I need to use the mouseHover event for many controls in my form (100+) to update a label's text when I hover the mouse over any of these controls. My question is, is there any way to create some sort of a "function" that can handle this, so that I don't have to create a sub that handles MyControl.MouseHover for each of my controls that I want to modify it's MouseHover event, but instead have something that works like functions do, and I just type the name of the Control there and The text I want to change the Label to.

    If I wasn't clear in my question, tell me.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: MouseHover event for Multiple Controls?

    vb.net Code:
    1. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    2.         For Each ctrl In Me.Controls ' this is the form controls, panels, tabcontrols etc. must be added separately
    3.             AddHandler CType(ctrl, Control).MouseHover, AddressOf MseHover
    4.         Next
    5.     End Sub
    6.  
    7.     Private Sub MseHover(sender As System.Object, e As System.EventArgs)
    8.         Me.Text = "I'm hovering over " & CType(sender, Control).Name
    9.     End Sub
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Re: MouseHover event for Multiple Controls?

    Super Awesome, with a little tweak to the function code I got it going, I was googling AddHandler because I had a feeling it'd be there, I just wasn't finding it.

    Thanks dunfiddlin, I really needed this for future reference as well

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width