PC Review


Reply
Thread Tools Rate Thread

MouseWheel event doesn't work on PictureBox

 
 
Jerry Spence1
Guest
Posts: n/a
 
      10th Nov 2007
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


 
Reply With Quote
 
 
 
 
New Member
Join Date: May 2012
Posts: 1
 
      7th May 2012
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Obtaining array of bytes from PictureBox or PictureBox.Handle Frustrated Microsoft Dot NET 0 13th Jun 2006 03:38 PM
Copy Image in picturebox to another picturebox =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= Microsoft VB .NET 0 15th Sep 2005 08:53 AM
no mousewheel event for picturebox? Rud Microsoft VB .NET 0 16th Nov 2004 08:25 PM
URI Formats are not supported when PictureBox.Image Loads, How to load http images to picturebox in windows application thedebugger Microsoft C# .NET 2 19th Oct 2004 09:21 AM
Picturebox over Picturebox Timothy Taylor Microsoft Dot NET Compact Framework 1 29th Aug 2003 12:22 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:30 AM.