C# winform在运行过程中鼠标左键移动控件位置

        Point _downPoint;
        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            _downPoint = new Point(e.X, e.Y);
        }

        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Control ctr = sender as Control;
                ctr.Location = new Point(ctr.Location.X + e.X - _downPoint.X, ctr.Location.Y + e.Y - _downPoint.Y);
            }
        }

 

posted @ 2019-02-12 14:00  Bridgebug  阅读(217)  评论(0)    收藏  举报