private Point start_p;             // 클릭시 마우스 위치
        private Point end_p;               // 마우스 이동할때 위치
        private bool mouse_move = false;   // 마우스가 드레그 상태인지 확인

        private void button2_MouseMove(object sender, MouseEventArgs e)
        // 마우스 이동시
        {
          Point th;   // 마우스의 현재위치를 계산하기 위한 폼의 위치
            if (mouse_move == true)
            {
                th = this.Location;
                end_p = ((Control)sender).PointToScreen(new Point(e.X, e.Y));
                Point tmp = new Point((button2.Location.X + (end_p.X - start_p.X)), (button2.Location.Y + (end_p.Y - start_p.Y)));
                start_p = ((Control)sender).PointToScreen(new Point(e.X, e.Y));
                
                button2.Location = tmp;
            }
        }

        private void button2_MouseDown(object sender, MouseEventArgs e)
        // 마우스로 컨트롤 클릭시
         {
            mouse_move = true;
            start_p = ((Control)sender).PointToScreen(new Point(e.X, e.Y));
        }

        private void button2_MouseUp(object sender, MouseEventArgs e)
        // 컨트롤에서 마우스 놓았을 때 
         {
            mouse_move = false;
        }
Posted by 아르다