我想用手指在屏幕上滑动一个球。我得到了光标位置,但是当我滑动时,球没有跟随我的手指。此外,我有几个球。(暂时没有,但我已经计划好了)
我的代码:
C#
private void MouseMoving(object sender, MouseEventArgs e)
{
if (sender.GetType() == typeof(Image))
{
System.Windows.Point cursorpos = e.GetPosition(null);
Image realSender = (Image)sender;
// MessageBox.Show(cursorpos.X.ToString());
// MessageBox.Show(cursorpos.Y.ToString());
Canvas.SetLeft(realSender, cursorpos.X);
Canvas.SetTop(realSender, cursorpos.Y);
Canvas.SetZIndex(realSender, idx++);
}
}
XAML
<Image Name="image1" Stretch="Fill" Source="/bal.png"
MouseMove="MouseMoving" Grid.ColumnSpan="4"
Canvas.Left="337" Canvas.Top="239"/`>