0

I have been poking around to understand how can I scroll the MDI Form with the Mouse Wheel event.

so I was able to capture and wire the event call. However, when the Child Form appears the MDI Form (Parent) gets its vertical scroll bar automatically.

And when I capture the mouse wheel as below, pretty much all the values of the scrollbar are 0s, even when I try to change them.

so I am not sure if I am missing the point or doing something completely wrong!

private void Form_MouseWheel(object sender, MouseEventArgs e)
{
    Debug.WriteLine("Vertical Value:" + this.VerticalScroll.Value);
    Debug.WriteLine(" MouseEventArgs Y:" + e.Y);
    Debug.WriteLine("AutoScrollPosition:" + this.AutoScrollPosition);

    this.VerticalScroll.Value += 1;
    this.AutoScrollPosition = new 
    Point(AutoScrollPosition.X, AutoScrollPosition.Y + 1);
 }

OutPut:

Vertical Value:0
MouseEventArgs Y:405
AutoScrollPosition:{X=0,Y=0}
Unis
  • 365
  • 1
  • 4
  • 13
  • 1
    The Parent of a MDI child Form is the `MDIClient`, not the MDI Form. The ScrollBars also belong to the `MDIClient`. – Jimi Aug 31 '22 at 22:38
  • @Jimi thank you. I did not know that. Would you please let me know how can I access the `MDIClient` from the Form? My goal is to be able to scroll the `MDI Container` with the Mouse wheel. – Unis Sep 01 '22 at 08:03
  • Well, you *could* replace the MdiClient with a custom one, but unfortunately the MdiClient class is `sealed`, you cannot derive from it. You can make your MDI Form implement `IMessageFilter` (as shown [here](https://stackoverflow.com/a/71143588/7444103)), trap `WM_MOUSEWHEEL` and post (`PostMessage()`) `WM_VSCROLL = 0x0115` with LParam set to either `SB_LINEDOWN = 1` or `SB_LINEUP = 0` based on the sign of the Delta. See here: [Set Delta in a WM_MOUSEWHEEL message to send with PostMessage](https://stackoverflow.com/a/60213791/7444103) for some info about it. – Jimi Sep 01 '22 at 10:48

0 Answers0