C#动态创建的picturebox控件如何实现拖动
我用需要在winform窗体中动态创建一组picturebox控件。并且都要能拖拽 。这个功能怎么实现呢? C#?? C# WINFORM? 控件 拖拽
[解决办法]
private bool isDragging = false; //拖中
private int currentX = 0, currentY = 0; //原来鼠标X,Y坐标
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isDragging = true; //可以拖动
currentX = e.X;
currentY = e.Y;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
pictureBox1.Top = pictureBox1.Top + (e.Y - currentY);
pictureBox1.Left = pictureBox1.Left + (e.X - currentX);
}
}