Custom mouse cursor size in WPF
Asked Answered
O

1

10

We are developing an application that must be used by people that may have some visual problem involving the use of kinect to move the cursor, so we need to make it bigger than usual. However, this application does not interfaces directly with kinect, so we can't use its APIs.

We are programming in C# (.NET 4.5) using WPF. The problem is that the default cursor size cannot be bigger than 32x32 pixel or 64x64 pixel in high res devices.

We first tried to make the actual mouse cursor invisible and then use a Graphics object, taken using Graphics.FromHwnd(applicationWindowHandler). It succeeds to draw the image but it leaves the trail of the past cursor positions.

Is there a way to do using the regular windows mouse cursor, or at least a way to remove the trail (like an "invalidate" method that force the current window to refresh)?

We already tried these solutions but with no luck:

www.hsys.com/CustomCursorArticlePart1.htm

www.hsys.com/CustomCursorArticlePart2.htm

csharparticles.blogspot.it/2005/03/custom-drawing-cursors.html

Overmaster answered 11/9, 2013 at 13:52 Comment(2)
Did you use Cursor="None" or ForceCursor="None"? I don't see any trail if I use one of them.Tortile
You don't see any trail if the "icon" actually is the mouse cursor one. But you can't make it bigger than 32x32 or 64x64. If you use the Graphics object taken from the main WPF window to draw a custom image that follows the mouse coords (hiding the real mouse cursor), than you have a trailOvermaster
S
2

Couldn't you just use a Canvas control that covers the entire window, set the cursor to none and then put an Image control with a suitably large cursor image in the Canvas, with its Left and Top properties bound to the cursor's X and Y coordinates relative to the Canvas??

Shelley answered 11/9, 2013 at 14:23 Comment(3)
yes, we tried, but there two main problems: 1- inside our main window we use only relative positions (and Canvas, afaik, use absolute positioning), 2-once we wrap the whole content in a Canvas, every child component seems to enlarge, like a zoom effect (which is weird)Overmaster
That is weird, but why wrap all the content in a Canvas? Why not create a grid, put your content in that, followed by the Canvas (also in the grid) at the very end or by giving it a high Grid.ZIndex value so that it is always rendered on top of your content. The content doesn't have to be -in- the canvas, the canvas just has to be in front of it. Secondly: why not just use absolute positions for the Image's position, and relative ones for the rest?Shelley
we tried your solution and it worked as well, but we choosed to use Uwe's suggested tutorial because substituting directly the mouse cursor gives us less delay and slightly better performances! But thanks anyway, your comments really helped us :)Overmaster

© 2022 - 2024 — McMap. All rights reserved.