C# 如何在面板中移动picturebox?
我想在面板中移动picturebox,但在窗体中有一个按钮。调用事件键时,面板中的picturebox无法移动?我不明白?帮帮我 我要移动图片盒C# 如何在面板中移动picturebox?,c#,winforms,C#,Winforms,我想在面板中移动picturebox,但在窗体中有一个按钮。调用事件键时,面板中的picturebox无法移动?我不明白?帮帮我 我要移动图片盒 从Form1.cs[Design]中双击要单击的按钮,该按钮可移动球。这将自动生成一个事件。通过将pictureBox.Location设置为新点来移动球 private void button2_Click(object sender, EventArgs e){ int new_x_location = 12; in
从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);
}
这将移动pictureBox,就像传送它一样。如果你想让它作为动画在屏幕上移动,你需要从这里开始查找线性插值:这是使用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);
}
}
请显示您的代码好吗?不清楚发生了什么事!我确实添加了图像。谢谢,这样更好,但我想看看代码。