Dvlnblk

I am trying to calculate the difference bettween the mouse and another object called _secondMouse but I am running into Casting Errors, anyone know how I can do this

Current Code:

_point = Mouse.GetPosition(this);

_mouseDiff = (Double)_point + (Double)_secondMouse;

ERROR:

Cannot convert type 'System.Windows.Point' to 'double'

Thanks in advance!



Re: Windows Presentation Foundation (WPF) calculating the difference bettween two Points

Douglas Stockwell

Assuming _point and _secondMouse are both Point while _mouseDiff is Double, you probably want something like:

_mouseDiff = (_point - _secondMouse).Length;

The result of the subtraction of one Point from another is a Vector. Length returns the difference between the two points.





Re: Windows Presentation Foundation (WPF) calculating the difference bettween two Points

Dvlnblk

I changed _mouseDiff to a Vector and copied your code and got this error:

Cannot implicitly convert type 'double' to 'System.Windows.Vector'

Code:

_mouseDiff = (_point - _secondMouse).Length;

Any ideas


Thanks for the help BTW





Re: Windows Presentation Foundation (WPF) calculating the difference bettween two Points

Dvlnblk

Wait, I gotcha, I shouldn't have turned _mouseDiff into a Vector but rather left it a Double. Works perfect now! Thanks!