Get Mouse Position on Canvas (But NOT on window)?
Doesn't this work?
Point p = Mouse.GetPosition(canvas);
The position of the mouse pointer is calculated relative to the specified element with the upper-left corner of element being the point of origin,
Hi the important thing is the
NOT on the Window
the canvas is part of the window as well.one example:
- the Window.AllowsTransparency state is on true
- the Window.Background is #00000000 (completely transparent)
- the Window.Style is None
- the Window.State is Maximized and
- there are NO controls or elements on the window!
...so if you start the application you will see Nothingnow tell me how to get the mouseposition on the screen in pixel
!Warning!if you juse Mouse.GetPosition(this);
it will return x0 y0 every time
so I solved the Problem by using System.Windows.Forms.Control.MousePosition
it's a bit a mix of wpf and Windows.Forms but I've given up xD.
Sorry for yelling :/
To make it easy for me I made a Extension:
<DebuggerHidden> _<System.Runtime.CompilerServices.Extension> _Public Function toWfpPoint(p As System.Drawing.Point) As Point Return new Point(p.X, p.Y)End Function
Now I just can juse it like this:
Dim MousPos As Point = System.Windows.Forms.Control.MousePosition.toWfpPoint