作者: jiayou168
查看: 1080|回复: 0

[求助] 【求助】图片做标题,如何实现鼠标放到图片上移动窗体?

[复制链接]
jiayou168 发表于 2016-5-17 11:44:28 | 显示全部楼层 |阅读模式
查看: 1080|回复: 0
本帖最后由 jiayou168 于 2016-5-17 14:16 编辑

用图片做标题,怎么实现图标放上去可以移动窗体呢?

【求助】图片做标题,如何实现鼠标放到图片上移动窗体?

【求助】图片做标题,如何实现鼠标放到图片上移动窗体?


【求助】图片做标题,如何实现鼠标放到图片上移动窗体?

【求助】图片做标题,如何实现鼠标放到图片上移动窗体?


已搞定

private Point _mousePoint;
        private int topA(Control cc)
        {
            if (cc == null || cc == this) return 0;
            if (cc.Parent == null || cc.Parent == this)
                return cc.Top;
            else
                return topA(cc.Parent) + cc.Top;
        }
        private int leftA(Control cc)
        {
            if (cc == null || cc == this) return 0;
            if (cc.Parent == null || cc.Parent == this)
                return cc.Left;
            else
                return leftA(cc.Parent) + cc.Left;
        }
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Top = MousePosition.Y - _mousePoint.Y;
                Left = MousePosition.X - _mousePoint.X;
            }
        }
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            Control cc = (Control)sender;
            if (e.Button == MouseButtons.Left)
            {
                _mousePoint.X = e.X + leftA(cc);
                _mousePoint.Y = e.Y + topA(cc);
            }
        }

回复 论坛版权

使用道具 举报

您需要登录后才可以回帖 登录 | 加入CSkin博客

本版积分规则

QQ|申请友链|小黑屋|手机版|Archiver|CSkin ( 粤ICP备13070794号

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-3-29 18:14, Processed in 0.782894 second(s), 33 queries , Gzip On.

快速回复 返回顶部 返回列表