Hi All
I have a Form with a panel in it.
I want to move an image according to the cursor position.
I have a mouse over function, but how do i do the calculation right ? since the cursor position is from the monitor and the picturebox is from the panel
You can use Control.PointToClient method to convert screen coordinates to the local ones. If you follow the MSDN link there's a good example that shows how to do that.
Point localCoordinates = myPictureBox.PointToClient(mouseScreenCoordinates);
Related
I have a WPF application where I used DevExpress charts to display some data. I want to get rid of them and use LiveCharts, but I want to display a circle in the chart point closest to the mouse cursor when it is inside the chart. I have tried sections and I can show lines that cross in the point, but I can't mark that point as it automatically does when you hover over it. Is there a way to do this without changing the source code?
I think you can get your answer from this example.
By calculating the closest point to your mouse (like in the example, you can then change the style of your chart point. In the example, the x-axis lable at the specific point gets highlighted.
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??
In order to work with an image I need to make the user select certain(4) coordinates within a Image Box and afterwards save that coordinate data and close the window. The project is using C# and WPF. Sadly google is giving me a lot of unfocused solutions on this topic. Any suggestions/ links?
thanks
Point pos = Mouse.GetPosition(myElement); will give you the mouse position relative to the element.
I want to achieve the following with a WPF application (in a certain area/defined area):
When clicking and holding on the app, you can draw a square
You can do this as many times, but not overlap any squares
You can drag squares around the application
What do I need to achieve this, I assume a bunch of onclick/onmove's. Is there an easier way, such as using canvas? Any insight would be great.
You will have to use a canvas if you want the squares to appear where the user clicks and drags.
The mouse down event would define one corner and the mouse up the second. You'd have to constrain the movement of the cursor so that the x and y dimensions of the rectangle were the same.
On each mouse move event you'd have to check if the cursor were over one of the existing squares and prevent the square growing any further.
For the dragging of existing squares modify the mouse down event to check what's under the cursor. If it's the canvas start the square drawing mode, if it's a rectangle (square) then start the dragging mode. Again you'd need to use the mouse move event to check that the square doesn't intersect with any existing squares.
There's a code project article describing how to drag elements inside a Canvas: Dragging Elements in a Canvas
Speaking of ChrisF's mentioning of using a Canvas, I would suggest you use DragCanvas (found in the article)
I am using an old ActiveX control in my C# Win App.
it has a MouseUp event that its eventArgs is passing the X and Y of the point that we have clicked but for my scenario I am using its ItemClick event and its eventArgs does not have the info about X and Y.
but I need to know them to show my pop-up... so is there a way I can find out what is the location of X and Y that user has right-clicked so I can pass it to my contextMenuStrip.Show method.
Thanks
The Control class has a static readonly MousePosition property, this gives the mouse coordinates on the screen. You could use this to know where to position the ContextMenu.
From MSDN:
Control.MousePosition Property
Type: System.Drawing.Point
A Point that contains the coordinates of the
mouse cursor relative to the
upper-left corner of the screen.
Cursor.Position will get you the current screen coordinates of the cursor. For most uses this is good enough, even though the mouse can potentially move between the click and the handler being called.
You need to get the cursor position which gets the screen position, then call pointToClient from within the control to get the relevant point to the control. Aka. 0,0 is the top left of the control.
this.PointToClient(Cursor.Position);
+1 to other answers for leading me in the right direction.