2

I have form. I have enabled the transparency on the form and I have removed it's Title Bar and Border. Inside that i have created a Custom UI, Which have the same features like a window. Basically, my idea is to create custom window.

Everything is working as expected but only the windows dragging is not working. I am not sure how to enable it. I googled for this. But i didn't find any useful info for me.

Please help me to implement this window dragging.

Dinesh
  • 2,026
  • 7
  • 38
  • 60
  • wat about `mouse` events.... ?? Try to use `mouse` events to move the window. – Thorin Oakenshield Oct 22 '10 at 08:23
  • Default winform behavior is to drag a window by it's title bar, which you removed. Note that when users see a bar-less window they are less likely to drag&move it. If you still want this, you have to implement it yourself, for instance using the solution provided in Cyril's answer. – Marijn Oct 22 '10 at 08:36
  • possible duplicate of [Move a window on keypress + mouse (like linux ALT + mouse down)](http://stackoverflow.com/questions/3100711/move-a-window-on-keypress-mouse-like-linux-alt-mouse-down) – Hans Passant Oct 22 '10 at 09:00
  • possible duplicate of [Winforms - Click/drag anywhere in the form to move it as if clicked in the form caption](http://stackoverflow.com/questions/30184/winforms-click-drag-anywhere-in-the-form-to-move-it-as-if-clicked-in-the-form) –  Sep 10 '15 at 15:03

3 Answers3

5

I've implemented this behavior by capturing mousedown (uncapture on mouseup), and then mousemove.

Just move the form co-ordinates (left, top), equivalent amounts to the mouse movement (those events have the amount the mouse moved).

This worked fine for me.

Cyril Gupta
  • 13,505
  • 11
  • 64
  • 87
1
class YourForm : Form
{
     private const int WM_NCHITTEST = 0x84;
     private const int HTCLIENT = 0x1;
     private const int HTCAPTION = 0x2;

     ///
     /// Handling the window messages 
     ///
     protected override void WndProc(ref Message message)
     {
          base.WndProc(ref message);

          if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
               message.Result = (IntPtr)HTCAPTION;
     }
}
arpl
  • 3,505
  • 3
  • 18
  • 16
0

The easiest way is to process WM_NCHITTEST message and return HTCAPTION for the portions of your custom window which work like the title bar does in a normal window. Windows will do the rest.

Anton Tykhyy
  • 19,370
  • 5
  • 54
  • 56