# DragDrop Windows Forms in VB2008



## Bjornke (Dec 24, 2008)

Hi, I need help on the code to Drag and Drop an Entire Windows Form by Holding down the mouse button on the top bar and allowing the entire window to move around the screen (Like you do with other Windows Forms, such as IE7) until you release the left mouse button. The problem is am not using a Form Border, and have a PictureBox with a nice graphic in it at the top. As you can guess, I want the user to be able to click on the picture box, and while holding it, be able to move the entire Form around the screen.

If you need any other information, please tell me. Thanks.


----------



## Bjornke (Dec 24, 2008)

I am pretty sure this would have something to do with the:

Me.Location = MousePosition

Or with the DoDragDrop(dragdropevent.move) 

Type of code. I just need some insight on where to put things.

By the way, I am using Visual Studio 2008.


----------



## JimmySeal (Sep 25, 2007)

Simply add this code to your form's class:


```
Point dragStartPoint;

        private void StartDrag(object sender, MouseEventArgs e)
        {
            dragStartPoint = e.Location;
        }

        private void DragMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Left += e.X - dragStartPoint.X;
                this.Top += e.Y - dragStartPoint.Y;
            }
        }
```
Then set the picture box's _MouseDown _event to be StartDrag, and its _MouseMove _event to be DragMove. You can do the same for any other control that you want to use as a handle for dragging the form around the screen, including the form itself.


----------

