OnMouseWheel Event Not Working w/Runtime-Generated Controls

Hi all; first time posting so forgive any obvious mistakes or decorum oversights.

Summary:
Creating controls at runtime and laying them out on a form; using AddHandler to assign subs to control events. MouseMove and MouseUp work fine, but MouseWheel does not work. Desktop (not Web) app, VS2005, no add-ins, plug-ins, etc. Vanilla install of VB2005 EE. No error messages or warnings at design- or runtime.

Background:
I'm working on an app that dynamically defines and lays out controls at runtime based on the dimensions of the form (_resize event will also affect these controls). The code that manages the definition & layout also assigns event handlers to these controls using AddHandler. Nearly everything works just fine as I need it.

The only controls that are dynamically generated in this fashion are PictureBoxes. The handlers I assign cover the MouseMove, MouseUp, and MouseWheel events for each such created PB.

The Problem:
OnMouseWheel event code does not appear to be fired off correctly. There is no error or warning for the AddHandler line that associates the generic handler sub with the dynamically-generated control event, nor is there an unhandled runtime error when the mouse wheel is scrolled over the controls at runtime.

The code for the MouseMove and MouseUp events fires normally as expected.

Relevant Snippets:
In the runtime control declaration:

...

pic = New PictureBox
[...formatting, layout code for pic...]
AddHandler pic.MouseWheel, AddressOf handleMouseWheelPictureBox
AddHandler pic.MouseMove, AddressOf handleMouseMovePictureBox
AddHandler pic.MouseUp, AddressOf handleMouseUpPictureBox

...


The MouseWheel handler code:
Code Snippet

Friend Sub handleMouseWheelPictureBox(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)


doStuff(CType(sender, PictureBox).Tag, e.Delta / 120)
End Sub

Any help that you could provide would be enormously useful. Thanks in advance for your time!
[2684 byte] By [JasonPayne] at [2008-1-7]
# 1
I'm such an idiot. After searching through several other posts, it turns out that the culprit is that the controls are being laid out on a Panel, and as a result the controls and/or the parent panel never get the focus. I added code to the MouseMove sub that ensures that this is the case when the user moves over one of the pictureboxes, and now the MouseWheel code fires as expected.

I'm still a bit confused as to why this prevents MouseWheel from firing correctly, but has no impact on MouseUp or MouseMove. But at least my immediate problem is resolved.

JasonPayne at 2007-10-2 > top of Msdn Tech,Visual Basic,Visual Basic General...