views:

649

answers:

2

Hi, i am trying to make a c# WPF form where i can drag it around the screen by clicking on it and moving with the mouse. the forms characteristics include being completely transparent and containing only one image. This being said the window style is none and it is not displayed in the taskbar. So essentially all you can see when the app is running is a little image - and ideally i want to be able to drag it around the desktop if i click and hold the left mouse button and move it about.

Does anyone know a simple way i can accomplish this or have i overlooked a build in function?

Thanks.

+5  A: 

You can use the Window.DragMove method in the mouse down event of the window.

Josh Einstein
could you provide a code exmaple of how i could do this?
Grant
There is a code example in the documentation for the DragMove method that shows exactly what you're trying to do but it's literally 3 lines long - handle the MouseLeftButtonDown event of the window, call the DragMove method on the window.
Josh Einstein
+1  A: 

Previous answers hit on the answer, but the full example is this:

   private void Window_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.LeftButton == MouseButtonState.Pressed)
        {
            DragMove();
        }
    }
EPiddy