问题描述
我有一个表格,里面我有一个小的面板
名为播放
。我怎样才能链接面板用户的鼠标,所以它会移动,鼠标移动?
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?
我已经订阅 Player_MouseMove
到 Player.MouseMove
事件,但我想不出有多少有鼠标实际移动。只有这样我能想出的是有一个这样的:
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;
}
这似乎是pretty的愚蠢,有一个额外的变量,并计算不同的每次。完美的方式会像 Player.LinkToCursor();
或者这样的,但是如果没有自动化的方式,是有ATLEAST一个更好的办法
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:
Point difference = e.Location - (Size)previousLocation;
矢量算术;)
Vector-arithmetics ;)
这篇关于获取鼠标移动的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!