通过拖动pictureBox移动窗体 为什么 点pictureBox的时候 鼠标会自动定位到这个控件的左上角,窗体也跟着移动了 我想做到,不管点pictureBox哪个位置都能实现拖动!!!不要让他自动定位到左上角。

解决方案 »

  1.   

    //Point downPoint;        //private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
            //{
            //    downPoint = new Point(e.X, e.Y);        //}        //private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
            //{
            //    if (e.Button == MouseButtons.Left)
            //    {
            //        this.Location = new Point(this.Location.X + e.X - downPoint.X, this.Location.Y + e.Y - downPoint.Y);
            //    }
            //}代码是这样的  有没有解决办法!
      

  2.   

    哇,完全符合http://download.csdn.net/source/2266821
      

  3.   

    每次取得的坐标使用PictureBox的PointToScreen方法转换。
      

  4.   


    Point downPoint;  private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
      {
       downPoint = pictureBox1.PointToScreen(new Point(e.X, e.Y));  }  private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
      {
       if (e.Button == MouseButtons.Left)
       {
        Point pt=pictureBox1.PointToScreen(e.Location);
       this.Location = new Point(this.Location.X + pt.X - downPoint.X, this.Location.Y + pt.Y - downPoint.Y);
       downPoint=pt;
       }
      }