MouseWheel event doesn't work on PictureBox

Discussion in 'Microsoft VB .NET' started by Jerry Spence1, Nov 10, 2007.

  1. I have a picturebox on a form. All the events seems to work such as
    MouseEnter, MouseLeave etc. However I can not get the MouseWheel event to
    fire. I am hovering the mouse over the picture and turning the wheel. Does
    it not work like this?

    If I add a Form Mousewheel event then this does fire - even when the mouse
    is over the picturebox.

    -Jerry
     
    Jerry Spence1, Nov 10, 2007
    #1
    1. Advertisements

  2. Jerry Spence1

    Samuel K

    Joined:
    May 7, 2012
    Messages:
    1
    Likes Received:
    0
    I realize this thread is 4 1/2 years old, thus long forgotten by the original poster, but as it comes up in the first few results on Google when I was searching for the same question, I thought I would post the solution so as to help out anyone else who stumbles upon this thread in the same manner as myself.

    In order for the MouseWheel event to fire, the PictureBox must have focus, which it doesn't receive even by clicking on it, let alone hovering over it.

    Code:
        Private Sub PictureBox1_MouseEnter(sender As System.Object, e As System.EventArgs) Handles PictureBox1.MouseEnter
            PictureBox1.Focus()
        End Sub
    
    The code above will cause the PictureBox to gain focus whenever you mouse over it, allowing the MouseWheel event to fire.

    This does, of course, have the drawback of taking away the focus from whatever control previously had it. This could be a pain if you accidentally mouse over the image while trying to type in a TextBox, for instance.

    You can avoid that drawback by switching the PictureBox1.Focus code to a Picturebox1_MouseClick event, which would require the user to actively click on the image before using the mousewheel.
     
    Samuel K, May 7, 2012
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rud

    no mousewheel event for picturebox?

    Rud, Nov 16, 2004, in forum: Microsoft VB .NET
    Replies:
    0
    Views:
    473
  2. Guest

    MouseWheel Event

    Guest, Nov 28, 2004, in forum: Microsoft VB .NET
    Replies:
    0
    Views:
    231
    Guest
    Nov 28, 2004
  3. Adrian Game

    Getting MouseWheel Event in UserControl

    Adrian Game, Mar 16, 2005, in forum: Microsoft VB .NET
    Replies:
    2
    Views:
    459
    Guest
    Mar 17, 2005
  4. Qwert

    Turn off mousewheel event.

    Qwert, Jun 16, 2005, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    1,267
    Larry Lard
    Jun 16, 2005
  5. Guest

    Copy Image in picturebox to another picturebox

    Guest, Sep 15, 2005, in forum: Microsoft VB .NET
    Replies:
    0
    Views:
    751
    Guest
    Sep 15, 2005
Loading...

Share This Page