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);
            }
        }
发布了31 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/breakbridge/article/details/87085918