答案 0 :(得分:1)
这是使用 WIN32 API 的问题的答案,当您单击图片并将其拖到想要放在表单上的任何位置时,图片就会移动。
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(pictureBox1.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
答案 1 :(得分:0)
从Form1.cs [Design]中双击要单击的按钮以移动球。这将自动生成一个事件。通过将pictureBox.Location设置为新的点来移动球。
private void button2_Click(object sender, EventArgs e){
int new_x_location = 12;
int new_y_location = 34;
pictureBox1.Location = new Point(new_x_location , new_y_location);
}
这将移动图片框,就像在传送时一样。如果您希望它作为动画在屏幕上移动,则需要从此处开始查找线性插值:C# Lerping from position to position