C# Scrolling a Panel in windows forms

后端 未结 3 1982
礼貌的吻别
礼貌的吻别 2021-02-14 18:07

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

3条回答
  •  情深已故
    2021-02-14 18:57

    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.

提交回复
热议问题