MouseWheel event doesn't work on PictureBox

  • Thread starter Thread starter Jerry Spence1
  • Start date Start date
J

Jerry Spence1

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
 
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.
 
Back
Top