无边拖动窗体

这种方式使用的是自己写代码实现,将这段代码复制到界面代码中,然后选择窗体中的一个控件,比如Panel或者Label,将它们的MouseDown事件绑定代码中的MouseDown事件,MouseMove事件绑定代码中的MouseMove事件,即可。
Point mPoint;

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

    private void Panel_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);

        }
    }

猜你喜欢

转载自blog.csdn.net/Hat_man_/article/details/115340237
今日推荐