Custom mouse cursor size in WPF - c#

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

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??

Related

WPF - Get relative Canvas coordinates after a drag/drop operation?

In WPF, I have a custom "toolbox" which consists of Label controls and some vector icons docked to the left of the screen.
In the center, I have a Canvas control which I eventually am going to need to serialize out the relative coordinates (for other platforms) for this "designer surface".
Basic question, I can drag/drop controls from this psuedo-control box onto a Canvas but I need to know how to place this WPF control properly in the canvas, under where the mouse pointer is, realtive to the Canvas and not the screen or main Window.
What are the functions that needed to be called so that I can ensure that if I drop a Button control at 10%, 20% of the canvas, I get an actual location back and the button drops where expected?
Mouse events provide a Point structure.
Converting of positions can be done by Control.PointToScreen and TargetControl.PointToClient.

UI Automation: How to determine how far a scroll bar scrolls a control

I'm faced with a problem: I am trying to automate a control with UI Automation. The control is a viewer in a client application, which hooks into a service hosted remotely. As a result of some legacy design decisions, this viewer simply displays a bitmap on a canvas. When interactions occur (e.g. clicks), the position of the click is sent to the service, which uses the co-ordinates to work out where the click occurred, and react correspondingly. The result of this is a nightmare for UI test automation. There is no way of hooking directly into sub-controls, because they are simply painted on to the bitmap. I have found a back-end way of accessing information about what is in this canvas, but now I need to work out where, in this scrolling bitmap, those items appear, so I can interact with them. I use positional information based on the upper part of the control, but since I don't have access to the bounding rects of these sub-controls, as soon as I scroll, all this information becomes invalid. My main problem is that I can't work out how far the scroll bar moves the canvas. Since scroll bars in UIA only have values from 0-100 (despite the actual magnitude of the scrolling effect), I can't work out how far down the canvas I've moved from a known position (it would depend on how far the scroll bar can move at that given time - i.e. how many sub-controls have been rendered in the bitmap). Is there any way of working out the magnitude of the scroll event on this canvas? I know that this must be done internally - the scroll bar has to know how far to move the canvas, based on the actual size of the canvas. However, the bounding rect of the canvas only gives it's visible on-screen position - it doesn't indicate how big the underlying image is. I either need to get the full size of the bitmap (as if it was rendered fully on screen, without scrolling), or to know how much adjusting the scroll value effects the visible position of the image. Is there any way of working this out?

How can I draw a square around an object, like this, in my GUI editor?

I want to write a GUI editor in C# for AutoIt, but I am not good enough with C#. I want to draw a square (focused) around an object when any object in the GUI is pressed. Like this:
Is there any library to make easier to write this kind of thing?
Square is drawn with one of DrawRectangle functions. Each of them requires a pen. Usually we use ordinary solid pen, but you need a pen with changed DashStyle property. For dotted lines change this property to DashStyle.Dot. You can also experiment with DashPattern property.
To draw little squares around the big square you need one of FillRectangle functions. Each of them requires a brush. You need a white brush, which is conveniently predefined for you to use. After filling a rectangle, you have to draw a rectangle over it with the same dimensions. These two functions together give an impression of empty and lined rectangle.
To make little squares a little rounded, like they are in the image, you have to change a pen parameter used when calling DrawRectangle. Experiment with LineJoin, and other properties of the Pen class.
This is very hard for a simple question that you posted. There are a lot of things that you need to take care of.
First I would suggest to make a class that will have a Rectangle property since you can't subclass Rectangle because it is a structure.
You will need to handle the drawing, that is the simplest task as mentioned in the other answers so I'm not going to be specific about that.
Since you have small squares that indicate that the rectangle can be resized, you will have to implement method that checks whether the mouse point is within the big rectangle or some of the small suqares. In this case you should change your cursor to indicate the possibility of resizing.
To handle moving (but not resizing) of the rectangle you will have either to make a new small square with the sign for moving in all directions or you will handle that using cursor when the mouse position is within the Big Rectangle.
The main problem is identifying what to change when resizing, you have two options:(1) to change Location and Size properties or to change X, Y, Width and (2)Height properties of the rectangle. For instance, when you are moving top-right corner you should change both Location and Size in first case or Y and Width is you are using second option.
When you move the mouse while it is clicked, you should watch out in which direction mouse moves. If you split the viewport in quadrants where the center of your rectangle is the center of the Decartes coordinate system, by identifying in which quadrant is the mouse you will know which corner (or edge) of the quadrant you need to move.
Each mouse move will have to call Invalidate() because you can't use Xor like in C++. Therefore, when your Rectangle is displayed, you should be in a special mode where everything that not moves (not changes, everything except Rectangle and selected control) should be drawn to the Bitmap that is used between two redraws and you should only draw what is moving.
As you can see, there is a lot of things that should be taken care of. You should start with this only after you are sure that you have already implemented other parts of your program.

How do I draw a caret on an image?

In my application the user can write from keyboard on an image. Is it possible to display the caret on the image (as in TextBox for example)?
You've got 3 separate issues:
1) Drawing Text at arbitrary locations.
See MSDN DrawString Method
2) Merging two separate images (the original and the text) into one.
As far as I know the image host controls, that you're likely using to show the image, provide a bitmap object property, so you need to be able to save that bitmap object to a file once you've done the DrawString.
3) Draw the caret symbol at arbitrary locations
You can do this with basic drawing commands to create your own caret, that's using Graphics with Pens and Paths.
Then the issue is to make it flash (which means drawing what's underneath your caret again, then your caret etc)
I think there's options on the Pen object that might achieve this for you.
I would tackle each in turn then put them together.
If you are referring to the Caret (the blinking indicator which shows the position when inputting text), you probably have to use P/Invoke. You should start here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ff468799(v=vs.85).aspx

How to create moveable "free floating" panel that can freely move over the canvas and is partially transparent

The scenario is that i want the user to create a shape in a small panel that opens (the added shape can later be placed on the canvas), but for a better reference, i want the user to be able to move the semi-transparent panel somewhere on the canvas and then draw with the accurate reference.
Please tell me:
Which panel type to use
How to make it moving by clicking the mouse on the move button (not the whole panel as dragging will be used for drawing lines) and move it around.
How to make it semi transparent.
How to make it appear and disappear (this should be pretty simple)
How to somehow limit its movement inside the canvas so it cannot move on the ribbon
And I really really hope there will be something built-in in WPF that i'll be able to use, and i will not have to do it the hard way i.e. create a rectangle, and do customized hit testing on it to allow the user to draw on top of that rectangle, make that rectangle transparent, and add graphics items for the buttons and controls on that rectangle "panel".
I am asking this because i have never seen such feature in any Windows application and i have no idea what to use for this purpose and how to implement it. The closest thing to what i want is in Adobe Acrobat Pro, which is the small preview of the page that appears when i double click with the middle mouse button. It doesn't move, nor it is transparent or can be drawn upon, but scale and shape wise i want something similar.
You should be able to place a second Canvas inside of your main canvas, and place whatever UserControl you'd like with your "view" inside of it.
You'll have to handle the mouse click/drag for moving it around yourself, but otherwise, it should be very straightforward.

Categories

Resources