作者: jiayou168
查看: 1088|回复: 0
打印 上一主题 下一主题

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

[复制链接]
跳转到指定楼层
楼主
jiayou168 发表于 2016-5-17 11:44:28 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
查看: 1088|回复: 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);
            }
        }

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播
回复 论坛版权

使用道具 举报

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

本版积分规则

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

Powered by Discuz! X3.2  © 2001-2013 Comsenz Inc.  Designed by ARTERY.cn
GMT+8, 2024-5-20 16:12, Processed in 0.550484 second(s), 32 queries , Gzip On.

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