I want to prevent scrolling with the MouseWheel in a SplitterPanel with a scrollbar conditionally, but preserve the scrolling behaviour (as shown in the code below) how can I do this?
I have this in the code, but it doesn't prevent scrolling and give weird behaviour:
public DocForm()
{
InitializeComponent();
this.splitContainer.Panel2.MouseWheel += new MouseEventHandler(this.splitContainer_Panel2_MouseWheel);
}
private void splitContainer_Panel2_MouseWheel(object sender, MouseEventArgs e)
{
if ((ModifierKeys & Keys.Control) == Keys.Control)
{
float scaleDelta = e.Delta / SystemInformation.MouseWheelScrollDelta * 0.1f;
// Scale instead of scrolling
// ...
}
else
{
OnMouseWheel(e);
}
}



You can implement IMessageFilter in a Custom Control derived from SplitContainer, to suppress
WM_MOUSEHWHEEL(andWM_MOUSEHWHEEL, eventually), when the recipient of the message is one of the SplitterPanels (Panel2, here).It's probably simpler (IMO), because the SplitterPanel class is sealed (it shadows a lot of properties of its base class).
Call Application.AddMessageFilter() to add the filter and Application.RemoveMessageFilter() to remove it:
To replace the existing SplitContainer with this one, open the Designer.cs file of the parent Form, then replace the Field set to
new SplitContainer()withnew SplitContainerNoWheel()(or whatever name you decide to assign to this custom Control)