How can I scroll my panel using my mousewheel?

前端 未结 9 1555
情歌与酒
情歌与酒 2021-01-17 09:19

I have a panel on my form with AutoScroll set to true so a scrollbar appears automatically.

How can I make it so a user can use his mouse wheel to scroll the panel?

9条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 10:11

    In my case, the whole client area of the panel was occupied by UserControls (not a single pixel of the inner area visible, except the scrollbars).

    In this case the panel doesn't get the mouse-events and will never focus (apperently, clicking on the scrollbar does not count as "being inside the panel").

    I had to add the following lines to the constructor of my UserControl derived class:

    MouseEnter += delegate {
       Parent?.Focus();
    };
    

    Now it works fine, as I have no scrollable content in the UserControls.

提交回复
热议问题