If you create your own control derived from UserControl or ScrollControl or Form , you can use this simple solution:
protected override void OnMouseWheel(MouseEventArgs e) { if (this.VScroll && (Control.ModifierKeys & Keys.Shift) == Keys.Shift) { this.VScroll = false; base.OnMouseWheel(e); this.VScroll = true; } else { base.OnMouseWheel(e); } }
Description
If the control has AutoScroll and displays scroll bars, you will get the following behavior when scrolling the mouse wheel:
- If scrollbars are not included, it does nothing.
- If only the vertical scroll bar is enabled, it scrolls the vertical scroll bar.
- If only the horizontal scroll bar is enabled, it scrolls the horizontal scroll bar.
- If the vertical and horizontal scroll bars are enabled, it scrolls the vertical scroll bar.
Noting this behavior, I realized that this hack will override the OnMouseWheel of the control, then if the vertical scrollbar is turned on and Shift is held down, it disables the vertical scrollbar before calling base.OnMouseWheel . This will deceive control when scrolling the horizontal scrollbar (behavior 3, as shown above).
Alvin wong
source share