Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i try this code but it doesnt work and when i click at the title bar, it hides, i dont know what shoud i do.
C#
private bool Dragging = false;
private Point start_point = new Point(0, 0);

        private void UserControlDesign_MouseDown(object sender, MouseEventArgs e)
        {
            Dragging = true;
            start_point = new Point(e.X, e.Y);
        }

        private void UserControlDesign_MouseUp(object sender, MouseEventArgs e)
        {
            Dragging = false;
        }

        private void UserControlDesign_MouseMove(object sender, MouseEventArgs e)
        {
            if (Dragging)
            {
                Point p1 = new Point(e.X, e.Y);
                Point p2 = this.FindForm().PointToScreen(p1);
                Point p3 = new Point(p2.X - start_point.X, p2.Y - start_point.Y);
                this.FindForm().Location = p3;
            }
        }
Posted
Updated 10-Mar-13 21:38pm
v2

1 solution

The coordinate given in the MouseDown event are in the client space not the screen.
You do not need to transform the mouse coordinate using the PointToScreen method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900