首页 新闻 赞助 找找看

C# WinForm 计算空间相对于左上角的像素位置

0
[已关闭问题] 关闭于 2021-04-06 17:06

        private Point LocationOnScreen(Control c)
        {
            Point retval = new Point(0, 0);
            do
            {
                retval.Offset(c.Location);
                c = c.Parent;
            }
            while (c != null);
            return retval;
        }

这段代码不会计算

怎么计算控件相对于屏幕左上角的像素位置?

echo_lovely的主页 echo_lovely | 小虾三级 | 园豆:1420
提问于:2021-04-06 16:44
< >
分享
所有回答(1)
0
        private Point LocationOnScreen(Control c)
        {
            Console.WriteLine(c.PointToScreen(new Point(0,0)).ToString());//相对于0,0 位置的,带标题栏
            Point retval = new Point();
            do
            {
                retval.Offset(c.Location);
                c = c.Parent;
            }
            while (c != null);
            Console.WriteLine(retval.ToString());//不带标题栏
            return retval;
        }

echo_lovely | 园豆:1420 (小虾三级) | 2021-04-06 17:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册