New to Telerik UI for WinForms? Download free 30-day trial

How to modify mouse wheel scroll value in RadScheduler's MonthView

Environment

Product Version Product Author
2023.1.117 RadScheduler for WinForms Dinko Krastev

Description

By design, when using the mouse wheel the Month View in RadScheduler weeks section is scrolled by 1 week. There could be a requirement to change this value by more than 1 week.

Solution

By default, the SchedulerInputBehavior is responsible for processing the keyboard and mouse input. In this case, we can create a custom input behavior and override the HandleMouseWheel() method. Inside the method, you can offset the view by 2 weeks instead of 1.


public class MySchedulerInputBehavior : SchedulerInputBehavior
{
    public MySchedulerInputBehavior(RadScheduler scheduler)
        : base(scheduler)
    {
    }
    public override bool HandleMouseWheel(MouseEventArgs args)
    {
        // return base.HandleMouseWheel(args);
        if (args.Delta > 0)
        {
            //this.Scheduler.ViewElement.Scroll(true);
            SchedulerMonthView monthView = this.Scheduler.GetMonthView();
            SchedulerMonthView offsetView = (SchedulerMonthView)monthView.OffsetView(-2);
            monthView.StartDate = offsetView.StartDate;
        }
        else
        {
            //  this.Scheduler.ViewElement.Scroll(false);
            SchedulerMonthView monthView = this.Scheduler.GetMonthView();
            SchedulerMonthView offsetView = (SchedulerMonthView)monthView.OffsetView(2);
            monthView.StartDate = offsetView.StartDate;
        }
        return false;
    }
}


Public Class MySchedulerInputBehavior
    Inherits SchedulerInputBehavior

    Public Sub New(ByVal scheduler As RadScheduler)
        MyBase.New(scheduler)
    End Sub

    Public Overrides Function HandleMouseWheel(ByVal args As MouseEventArgs) As Boolean
        If args.Delta > 0 Then
            Dim monthView As SchedulerMonthView = Me.Scheduler.GetMonthView()
            Dim offsetView As SchedulerMonthView = CType(monthView.OffsetView(-2), SchedulerMonthView)
            monthView.StartDate = offsetView.StartDate
        Else
            Dim monthView As SchedulerMonthView = Me.Scheduler.GetMonthView()
            Dim offsetView As SchedulerMonthView = CType(monthView.OffsetView(2), SchedulerMonthView)
            monthView.StartDate = offsetView.StartDate
        End If

        Return False
    End Function
End Class

See Also

In this article