L
L
lucky_e32015-06-12 10:32:21
Mouse
lucky_e3, 2015-06-12 10:32:21

How to get mouse coordinates relative to Canvas (C# WPF)?

How to get mouse coordinates relative to Canvas (C# WPF)? and give out coordinates relative to the shape (starting from the upper left corner). In my case, I have a Canvas that is larger than the form. You need to display the mouse coordinates on the Canvas itself, from its upper left corner...
e.GetPosition(null).Xe.GetPosition(null).Y;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2015-06-12
@lucky_e3

Espleth Regarding WinForms - you can do without magic constants (which will inevitably be different on different OSes, with different themes and with different DPIs, i.e. it is basically impossible to use the same value), for this there is ClientSize
lucky_e3 Regarding WPF - absolutely it's not clear why you passed null to GetPosition instead of your canvas: written in black and white https://msdn.microsoft.com/en-us/library/ms591423%... - returns the position relative to the specified element. Canvas is a FrameworkElement, so is IInputElement. Therefore, request a position relative to the canvas and do not need constants.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question