Winform窗体拖动

Posted xamarin-oz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Winform窗体拖动相关的知识,希望对你有一定的参考价值。

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窗体拖动的主要内容,如果未能解决你的问题,请参考以下文章

winform 关于无边框和拖动窗体边缘改变尺寸的 踩坑笔记

winform 中怎样让窗体能拖动(移动),但是不改变窗体的大小(宽和高)

C# winform 控件拖动问题

Winform窗体拖动

WinForm拖动没有标题栏窗体的方法

c# WINFORM窗体如何设置才可以不能随意拖动大小