| |

VerySource

 Forgot password?
 Register
Search
View: 602|Reply: 1

Drag problem

[Copy link]

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-3-5 17:00:02
| Show all posts |Read mode
bool isMouseDown = false;
        Point mouseOffset;

private void label1_MouseUp (object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isMouseDown = false;
            }
        }

        private void label1_MouseMove (object sender, MouseEventArgs e)
        {
            if (isMouseDown)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset (mouseOffset.X, mouseOffset.Y);
                this.Location = mousePos;
            }
        }

        private void label1_MouseDown (object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOffset = new Point (-e.X, -e.Y);
                isMouseDown = true;
            }
        }


I want to implement a Label drag, but as soon as I drag the mouse to the 0,0 coordinates of the Form, what is going on?

Besides, how can you drag the controls?
Reply

Use magic Report

2

Threads

29

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-21 23:45:01
| Show all posts
It is recommended that you use the hittest method to live the position of the mouse
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list