实现窗口随鼠标移动而移动

 private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (!moveFlag && e.Clicks >= 1)
                moveFlag = true;
            x = e.X;
            y = e.Y;
            base.OnMouseDown(e);
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (moveFlag && (e.Button == MouseButtons.Left))
                this.SetBounds(Left + e.X - x, Top + e.Y - y, this.Width, this.Height);
            base.OnMouseMove(e);
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (moveFlag)
                moveFlag = false;
            base.OnMouseUp(e);
        }

 

posted @ 2012-12-18 15:05  qin孑  阅读(168)  评论(0编辑  收藏  举报