码迷,mamicode.com
首页 > Windows程序 > 详细

Winform窗体拖动

时间:2019-07-27 12:30:33      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:ini   ane   min   sed   control   idt   leave   this   cursor   

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);
        }

 

Winform窗体拖动

标签:ini   ane   min   sed   control   idt   leave   this   cursor   

原文地址:https://www.cnblogs.com/Xamarin-Oz/p/11254386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!