Skip to main content
A newer version of this page is available. .

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(MouseEventArgs e) - occurs when the user moves the mouse pointer over a control.
  • OnMouseDown(MouseEventArgs e) - occurs when the user presses the mouse button.
  • OnMouseUp(MouseEventArgs e) - occurs when the user releases the mouse button.
  • OnMouseWheel(MouseEventArgs 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(MouseEventArgs 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 MouseEventArgs 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.