Is it possible to make it so that the form can be moved with the mouse behind its main window, even if it has hidden borders?

ps + more to all this so that it was Resizable as well.

  • one
    this.DragMove () - I smoke, but the truth is, I only write on wpf - johniek_comp

1 answer 1

Of course this is possible. One option is to send a WM_NCLBUTTONDOWN message to the window to click the mouse, which signals that the left mouse button is pressed outside the client part of the window, that is, on hidden borders. However, before this action it is necessary to remove the "capture" of the cursor by the window, otherwise the message will be simply ignored.

 private const int WM_NCLBUTTONDOWN = 0xA1; private const int HTCAPTION = 0x2; protected override void OnMouseDown(MouseEventArgs e) { Cursor = Cursors.Hold; Capture = false; Message msg = Message.Create(Handle, WM_NCLBUTTONDOWN, (IntPtr)HTCAPTION, IntPtr.Zero); DefWndProc(ref msg); Cursor = Cursors.Default; } 

With the resizing will have to tinker longer, especially if it is done on the same form. As an option - first make a resize only for the lower right corner. You'll have to override the window procedure Form.WndProc and process the WM_NCHITTEST message WM_NCHITTEST . By the way, the first problem can also be solved in this place. See here for more details.