I have a circle when mousemove I can get e.GetPosition(this). But how to programmatically get the angle relative to the center of the circle ?
I saw on the internet some sample clocks with binding in XAML. That’s not what I want, I want to get the angle value from mouse position relative to the center of a circle.
This is what I tried:
private void ellipse1_MouseMove(object sender, MouseEventArgs e)
{
Point position = e.GetPosition(this);
double x = position.X;
double y = position.Y;
double angle;
double radians;
radians = Math.Atan2(y, x);
angle = radians * (180 / Math.PI);
}
Angle doesn’t seem correct NEVER get 0 nor 90 180.
OK, the MouseEventArgs expose the function ‘GetPosition’ which asks for a UI element that will give you the relative mouse position. This is basically what you want to do.
It seems that from your comments and the rest of the posts that you can handle the actual angle computation part yourself now that you have the right information. As far as the units are concerned, WPF uses a device independent system of coordinates. So a circle with a radius of 50 will not necessarily be 50 pixels. It all depends on your system, screen resolution, etc. It’s all kind of boring, but this will explain some it for you if you are really interested.
http://msdn.microsoft.com/en-us/library/ms748373.aspx