Input Behavior
The SchedulerInputBehavior is responsible for processing the keyboard and mouse input in RadScheduler.
Below are the methods which handle the respective events:
HandleMouseDown
HandleMouseMove
HandleMouseUp
HandleNavigationKey
HandleMouseWheel
HandleMouseEnter
HandleMouseLeave
HandleCellElementDoubleClick
HandleAppointmentElementDoubleClick
HandleCellElementKeyPress
Each of these methods can be overridden and the instance of the SchedulerInputBehavior used in RadScheduler can be replaced with a custom one. This allows you to modify the default behavior of the control. The following example demonstrates how to alter the default behavior and allow moving appointments via CTRL + arrow keys. In order to accomplish this, we need to inherit the SchedulerInputBehavior class and override the HandleKeyDown method:
Custom Input Behavior
public class MySchedulerInputBehavior : SchedulerInputBehavior
{
public MySchedulerInputBehavior(RadScheduler scheduler)
: base(scheduler)
{
}
public override bool HandleKeyDown(KeyEventArgs args)
{
bool isControl = (args.Modifiers & Keys.Control) == Keys.Control;
IEvent selectedAppointment = this.Scheduler.SelectionBehavior.SelectedAppointment;
if (isControl && selectedAppointment != null)
{
if ((args.KeyData & Keys.Up) == Keys.Up)
{
selectedAppointment.Start = selectedAppointment.Start.AddHours(-1);
selectedAppointment.End = selectedAppointment.End.AddHours(-1);
}
else if ((args.KeyData & Keys.Down) == Keys.Down)
{
selectedAppointment.Start = selectedAppointment.Start.AddHours(1);
selectedAppointment.End = selectedAppointment.End.AddHours(1);
}
}
return base.HandleKeyDown(args);
}
}
Public Class MySchedulerInputBehavior
Inherits SchedulerInputBehavior
Public Sub New(scheduler As RadScheduler)
MyBase.New(scheduler)
End Sub
Public Overrides Function HandleKeyDown(args As KeyEventArgs) As Boolean
Dim isControl As Boolean = (args.Modifiers And Keys.Control) = Keys.Control
Dim selectedAppointment As IEvent = Me.Scheduler.SelectionBehavior.SelectedAppointment
If isControl AndAlso selectedAppointment IsNot Nothing Then
If (args.KeyData And Keys.Up) = Keys.Up Then
selectedAppointment.Start = selectedAppointment.Start.AddHours(-1)
selectedAppointment.[End] = selectedAppointment.[End].AddHours(-1)
ElseIf (args.KeyData And Keys.Down) = Keys.Down Then
selectedAppointment.Start = selectedAppointment.Start.AddHours(1)
selectedAppointment.[End] = selectedAppointment.[End].AddHours(1)
End If
End If
Return MyBase.HandleKeyDown(args)
End Function
End Class
Now we need to assign this new input behavior to the SchedulerInputBehavior property of RadScheduler:
Set Behavior
scheduler.SchedulerInputBehavior = new MySchedulerInputBehavior(scheduler);
scheduler.SchedulerInputBehavior = New MySchedulerInputBehavior(scheduler)
You can see the result below: