Skip to main content

Mouse Services

  • 2 minutes to read

The IMouseHandlerService in the XtraScheduler provides the capability to respond to mouse events. It has the following delegates:

  • OnMouseMove(PortableMouseEventArgs e) - occurs when the user moves the mouse pointer over a control.
  • OnMouseDown(PortableMouseEventArgs e) - occurs when the user presses the mouse button.
  • OnMouseUp(PortableMouseEventArgs e) - occurs when the user releases the mouse button.
  • OnMouseWheel(PortableMouseEventArgs e) - occurs when the mouse wheel moves.

To handle these events you should first create a new class inherited from the DevExpress.Services.MouseHandlerServiceWrapper and override its methods as needed. The following code snippet illustrates how this can be done:

using DevExpress.Services;
// ...
public class MyMouseHandlerService : MouseHandlerServiceWrapper
{
    IServiceProvider provider;

    public MyMouseHandlerService(IServiceProvider provider, IMouseHandlerService service)
        : base(service)
    {
        this.provider = provider;
    }

    public override void OnMouseWheel(PortableMouseEventArgs e)
    {
        // Do something when the wheel is rotated.
        base.OnMouseWheel(e);
    }
}

The provider is the SchedulerControl instance that provides the service.

This class will replace the existing service that handles the mouse events.

The following code sample replaces the existing mouse handling service of the XtraScheduler with a custom one.

using DevExpress.Services;
// ...
IMouseHandlerService oldMouseHandler = 
    (IMouseHandlerService)schedulerControl1.GetService(
        typeof(IMouseHandlerService));
if (oldMouseHandler != null)
{
    MyMouseHandlerService newMouseHandler = 
        new MyMouseHandlerService(schedulerControl1, oldMouseHandler);
    schedulerControl1.RemoveService(typeof(IMouseHandlerService));
    schedulerControl1.AddService(typeof(IMouseHandlerService), newMouseHandler);
}

A PortableMouseEventArgs object specifies which mouse button is pressed, how many times the mouse button was pressed and released, the coordinates of the mouse, and the amount the mouse wheel moved.