Current page: Code snippets » C#, .NET » MouseFilter component

kick it on DotNetKicks.com

MouseFilter component

The MouseFilter component provides functions to manipulate the mouse behaviour in applications. At the moment these are the following:

Hiding the mouse cursor after a while of inactivity

In fullscreen applications it may be useful to hide the mouse cursor when not using it. Therefore all Windows messages sent to the running application are monitored and the cursor is hidden when the mouse wasn’t moved for a while. Moving the mouse immediately shows the cursor again, until the next inactivity timeout. This function can be activated with the AutoHideCursor property. Additionally, the events MouseHidden and MouseShown notify when the cursor has been hidden resp. shown.

Dispatching of mouse wheel input to the control below the mouse cursor

Normally, mouse wheel input always goes to the control which holds the keyboard input focus. But since that wheel is mounted to the mouse and not the keyboard, it should follow the mouse cursor’s position more than the keyboard focus. Due to the way how Windows sends the corresponding messages however, you cannot scroll in an inactive window even with the cursor over it. This function can be activated with the DispatchMouseWheel property.

In general, you only need to add an instance of the MouseFilter component to one of your application’s forms in order to use these functions.

.NET Compatibility: 2.0, 3.5

Download

As this component uses several files that I usually employ in my own applications, I’m offering a simple example application for download only. It contains the full required source code of the component and also demonstrates its usage. The component’s files are located in the Unclassified subdirectory.

[o] Example application source code (Visual Studio 2005 C# project, 19 kB, September 18th 2009)

Licence, terms of use

This programme is released under the terms of the GNU General Public License (GPL), version 2 or later.

Ausblenden
Statistik wird geladen...