I have a form and inside it I got a small Panel called Player. How can I “link” the panel to user’s mouse, so it will move as the mouse moves?
I’ve already subscribed Player_MouseMove to Player.MouseMove event but I can’t figure out how much has the mouse actually moved. Only way I can come up with is to have a such:
private Point previousLocation;
private void Player_MouseMove(object sender, MouseEventArgs e)
{
int differenceX, differenceY;
differenceX = e.X - previousLocation.X;
differenceY = e.Y - previousLocation.Y;
previousLocation = e.Location;
}
This seems pretty stupid, having an extra variable and calculating the difference everytime. Perfect way would be like Player.LinkToCursor(); or such, but if there’s no automated way, is there atleast a better way?
Looking at http://msdn.microsoft.com/en-us/library/system.windows.forms.mouseeventargs.aspx I can’t see anything that would help you get this done any better.
There is however one thing you could do:
Vector-arithmetics 😉