Wednesday, June 16, 2004

Deriving from Panel woes

If you're deriving from Panel, set AutoScroll to true and set AutoScrollMinSize to some big numbers, you get a Panel with ScrollBars, right?
Right: everything works, but the OnMouseWheel event doesn't happen, and the mouse wheel don't work. After googling a lot, I happened to discover that the mouse wheel is only sent to controls when they have the focus (doh! it should be obvious!).
So, correcting this is a simple matter of SetStyle(ControlStyles.Selectable, true) and then, at some place (probably on OnMouseDown or OnMouseEnter), you call Focus().
Voilá! Instant mousewheel support on your Panel!

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?