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

c#拖动picturebox控件
如题,拖动的方法我已经写好了如下

bool whetherSelected = false;
        Point pt = new Point();
        private void pbBigImage_MouseDown(object sender, MouseEventArgs e)
        {
            whetherSelected = true;
            pt = Cursor.Position;
            this.Cursor = System.Windows.Forms.Cursors.SizeAll;
        }

        private void pbBigImage_MouseMove(object sender, MouseEventArgs e)
        {
            if (whetherSelected)
            {
                Point newPoint = new Point();
                if (pbBigImage.Width > panel2.Width) 
                {
                    newPoint.X = pbBigImage.Left + Cursor.Position.X - pt.X;
                }
                if (pbBigImage.Height > panel2.Height) 
                {
                    newPoint.Y = pbBigImage.Top + Cursor.Position.Y - pt.Y;
                }
                pbBigImage.Location = newPoint; 
                pt = Cursor.Position;
            }
        }

        private void pbBigImage_MouseUp(object sender, MouseEventArgs e)