I\'m using VS2010, Windows 7
I have a panel with lots of picture-boxes. It has
AutoScroll = true
The scroll bars work properly when i d
Try
private void panel1_MouseEnter(object sender, EventArgs e)
{
panel1.Focus();
}
A couple things to try:
Make your Panel
have the first TabIndex
property. That is:
panel1.TabIndex = 0;
Obviously, the other controls on the form should be re-indexed properly.
Also, try adding the focus in the MouseDown event:
void panel1_MouseDown(object sender, MouseEventArgs e) {
if (!panel1.Focused)
panel1.Focus();
}
You could do MouseEnter, too, but that might be an odd user interface since moving the mouse over the panel would steal focus away from the current active control.
You shouldn't need to subscribe to the MouseWheel event. It should move the scrollbar automatically.
You scroll a Panel by assigning the AutoScrollPosition property. Beware that it uses negative values.
The reason the mouse wheel doesn't work is because neither the panel nor the picture boxes are focusable controls. You'll need to rework the panel control a bit to make it a focusable. You'll find the code in this answer.