views:

727

answers:

3

I have a VB.Net Winforms app which displays an MDI parent form and allows multiple child forms to be displayed on it. If the child forms extend beyond the screen height, a vertical scrollbar is automatically displayed on the right side of the MDI Parent & I can use this scrollbar to scroll the child forms into view.

But, the mousewheel has no effect on this scrollbar. How can I make the mousewheel scroll the child forms?

I can handle mousewheel events, but I am not sure what to do with them once I handle them to enable scrolling of the window.

A: 

Once you capture the mousewheel event, simply SetDisplayRectLocation() of the control being scrolled. Something like myControl.SetDisplayRectLocation(myControl.DisplayRectangle.X, myControl.DisplayRectangle.Y + MouseWheelDelta * ScrollAmount); (ScrollAmount is a constant you define -- start with 30 pixels). You also need to call AdjustFormScrollbars() on the main form as well to update the scroll bar location.

(Sorry, that's C# -- I don't know VB syntax)

Jon Watte
A: 

ScrollAmount is a constant you define... but, What about MouseWheelDelta?

A: 

Jon, your solution doesn't work for me.

I have a MDI parent form that hosts 4 child forms on vertical axis (one above the other). O course, the MDI parent needs a virtual space to display them, so the scrollbars appear.

I use this code to scroll the parent MDI form based on mouse wheel movements:

protected override void OnMouseWheel(MouseEventArgs e) {
    base.OnMouseWheel(e);
    this.SetDisplayRectLocation(DisplayRectangle.X, DisplayRectangle.Y + e.Delta);
    this.AdjustFormScrollbars(true);
}

Unfortunately, nothing happends, although the event is hit. Also, DisplayRectangle always starts at (0, 0) coordinates, event when I prevously move the scrollbars.

Ideas? Thanks.

Adi