usingSystem;usingSystem.Windows.Forms;usingdevexpress.xtraeditors;namespaceWindowsFormsApplication1 { Public classScrollhelper {ReadOnlyXtrascrollablecontrol _scrollablecontrol; PublicScrollhelper (Xtrascrollablecontrol scrollablecontrol) {_scrollablecontrol =ScrollableControl;} Public voidEnablescrollonmousewheel () {_scrollablecontrol.visiblechanged + =onvisiblechanged;} voidOnvisiblechanged (Objectsender, EventArgs e) {_scrollablecontrol.select (); Unsubscribefrommousewheel (_scrollablecontrol.controls); Subscribetomousewheel (_scrollablecontrol.controls); } Public voidSubscribetomousewheel (Control.controlcollection controls) {foreach(Control Ctrlinchcontrols) {Ctrl. MouseWheel+=OnMouseWheel; Subscribetomousewheel (CTRL. Controls); } } Public voidUnsubscribefrommousewheel (Control.controlcollection controls) {foreach(Control Ctrlinchcontrols) {Ctrl. MouseWheel-=OnMouseWheel; Unsubscribefrommousewheel (CTRL. Controls); } } voidOnMouseWheel (Objectsender, MouseEventArgs e) {DevExpress.Utils.DXMouseEventArgs.GetMouseArgs (E). Handled=true; varScrollvalue =_scrollablecontrol.verticalscroll.value; varLargeChange =_scrollablecontrol.verticalscroll.largechange; if(E.delta <0) _scrollablecontrol.verticalscroll.value+=_scrollablecontrol.verticalscroll.largechange; Else if(Scrollvalue < LargeChange) {_scrollablecontrol.verticalscroll.value =0; } Else{_scrollablecontrol.verticalscroll.value-=LargeChange;} } Public voidDisablescrollonmousewheel () {_scrollablecontrol.visiblechanged-=onvisiblechanged; Unsubscribefrommousewheel (_scrollablecontrol.controls); } }}
Call Method:
Private scrollhelper _scrollhelper; Public Constructor () { InitializeComponent (); New Scrollhelper (xtraScrollableControl1); _scrollhelper.enablescrollonmousewheel (); }
Xtrascrollablecontrol scroll bar control with mouse scrolling