日期:2014-05-17  浏览次数:20891 次

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);
            }
        }

------解决方案--------------------
引用:
C# code?12345678910111213141516171819202122Point oriPoint;        private bool isDragging = false; //拖中                private void pictureBox1_MouseDown(object sender, MouseEventArgs e) ……
没错,就是这样做的!