我怎么能用鼠标移动一个表格? [英] How can i move a forme with mouse?

查看:67
本文介绍了我怎么能用鼠标移动一个表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试这个代码但它不起作用,当我点击标题栏时,它隐藏,我不知道我该怎么做。

i try this code but it doesnt work and when i click at the title bar, it hides, i dont know what shoud i do.

private bool Dragging = false;
private Point start_point = new Point(0, 0);

        private void UserControlDesign_MouseDown(object sender, MouseEventArgs e)
        {
            Dragging = true;
            start_point = new Point(e.X, e.Y);
        }

        private void UserControlDesign_MouseUp(object sender, MouseEventArgs e)
        {
            Dragging = false;
        }

        private void UserControlDesign_MouseMove(object sender, MouseEventArgs e)
        {
            if (Dragging)
            {
                Point p1 = new Point(e.X, e.Y);
                Point p2 = this.FindForm().PointToScreen(p1);
                Point p3 = new Point(p2.X - start_point.X, p2.Y - start_point.Y);
                this.FindForm().Location = p3;
            }
        }

推荐答案

MouseDown事件中给出的坐标位于客户端空间而不是屏幕。

您不需要使用PointToScreen方法转换鼠标坐标。
The coordinate given in the MouseDown event are in the client space not the screen.
You do not need to transform the mouse coordinate using the PointToScreen method.


这篇关于我怎么能用鼠标移动一个表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆