UserControl containing PictureBox objects seems to disable mouse wheel scrolling

6

6tc1

Hi all, I've got a UserControl that contains a few PictureBox objects.
If I click on outside of the Picture in the UserControl, the scrolling
with the mouse button works - however, no amount of clicking on the
PictureBox objects will get that scrolling working. However, after I
click on outside of the PictureBox object, then click as many times as
I like on the PictureBox the scrolling with the mouse wheel continues
to work.

I found this:
http://www.experts-exchange.com/Pro...ages/Visual_Basic/VB_Controls/Q_20658733.html
From what I can determine the answer is to change the PictureBox
objects to Image objects. However, is there another way? I.E. could
extend the PictureBox class and use the following to catch mouse wheel
roll events?

this.MouseDown += new
System.WinForms.MouseEventHandler(this.pictureBoxMouseDown);

private void pictureBoxMouseDown(object sender,
System.WinForms.MouseEventArgs e) {
//some code to catch whether the mouse wheel is rolling
}

This strikes me as a little convoluted - is there an easier way?

Thanks,
Novice
 
6

6tc1

Solution:
Add the following to your class that extends PictureBox and it works:
private void PicBox_MouseEnter(object sender, EventArgs e)
{
if ( PicBox.Focused == false )
{
PicBox.Focus ();
}
}

I have no idea why Microsoft chose not to do something similar by
default - it seems strange to by default disable mouse events for
PictureBox controls.

Novice
 
6

6tc1

Sorry, that was a copy/paste with no explanation - you need to make the
above method the event handler for the MouseEnter event:
this.MouseEnter += new EventHandler(PicBox_MouseEnter);

And you need to change the PicBox to this in the above - like this:
private void PicBox_MouseEnter(object sender, EventArgs
e)
{
if ( this.Focused == false )
{
this.Focus ();
}
}

This all assumes you decide to extend PictureBox and not just add this
functionality to something that will contain an ordinary PictureBox -
both approaches will work.

Novice
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top