加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Winform窗体拖动

发布时间:2020-12-15 05:35:35 所属栏目:Java 来源:网络整理
导读:private void panelControl1_MouseDown( object sender,MouseEventArgs e) { if (e.Button == MouseButtons.Left) { currentFormWidth = this .Width; currentFormWidth = this .Height; isMouseDown = true ; mouSEOffset = new Point(MousePosition.X - th
private void panelControl1_MouseDown(object sender,MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                currentFormWidth = this.Width;
                currentFormWidth = this.Height;
                isMouseDown = true;
                mouSEOffset = new Point(MousePosition.X - this.Location.X,MousePosition.Y - this.Location.Y);
                this.Cursor = Cursors.SizeAll;
            }
        }

        private void panelControl1_MouseEnter(object sender,EventArgs e)
        {
            isMouseEnter = true;
        }

        private void panelControl1_MouseLeave(object sender,EventArgs e)
        {
            Point p = MousePosition;
            if (p.X - 10 <= this.Left || p.X + 10 >= this.Left + currentFormWidth || p.Y - 10 <= this.Top || p.Y + 10 >= this.Bottom)
            {
                isMouseEnter = false;
            }
        }

        private void panelControl1_MouseMove(object sender,MouseEventArgs e)
        {
            if (isMouseDown == true)
            {
                Point old = this.Location;
                this.Location = getMiniBallMoveLocation();
            }
        }

        private void panelControl1_MouseUp(object sender,MouseEventArgs e)
        {
            isMouseDown = false;
            this.Cursor = Cursors.Default;
        }

        private Point getMiniBallMoveLocation()
        {
            int x = MousePosition.X - mouSEOffset.X;
            int y = MousePosition.Y - mouSEOffset.Y;
            return new Point(x,y);
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读