C# Tips

C# Tip Article

How to scroll a panel using mouse wheel

Problem

How can we scroll a panel using mouse wheel in WinForms?

Solution

Set panel's AutoScroll property to true and set the panel to have focus. Panel does not have focus and it needs focus to scroll, so one way of doing it is to force focus when mouse is entering the panel area.

panel.AutoScroll = true;
panel.MouseEnter += (s, e) => panel.Focus();