I want to prevent a panel from scrolling when the mousewheel is used. I've tried setting the flag Handled
on the HandledMouseEventArgs
to false
, but that doesn't work.
In this repro code, we have one panel and one button.
using (var scrollTestForm=new Form())
{
var panel = new Panel() { Dock = DockStyle.Fill };
scrollTestForm.Controls.Add(panel);
var buttonOutsideArea = new Button();
buttonOutsideArea.Location = new System.Drawing.Point(panel.Width * 2, 100);
panel.Controls.Add(buttonOutsideArea);
panel.AutoScroll = true;
panel.MouseWheel += delegate (object sender, MouseEventArgs e)
{
((HandledMouseEventArgs)e).Handled = false;
};
scrollTestForm.ShowDialog();
}
When using the mouse wheel, the panel scrolls. How can I prevent it from scrolling?
m.WParam = IntPtr.Zero; m.Result = IntPtr.Zero;
and letbase.WndProc
get through. – Swifter