Move a window on keypress + mouse (like linux ALT + mouse down)

后端 未结 2 1281
星月不相逢
星月不相逢 2021-01-25 20:24

Simple, i want to move a windows pressing ALT+MOUSE, like linux os (ALT+drag).

It\'s possible to pass a win32 api (move api) to the windows interested clicking on it?

2条回答
  •  迷失自我
    2021-01-25 20:55

    You can do this by trapping the WM_NCHITTEST message that Windows sends to see what area of the window got clicked. You can fool it by returning HTCAPTION and it will dutifully perform the mouse actions you'd normally get when clicking the caption of a window. Including moving the window. Paste this code into your form:

        protected override void WndProc(ref Message m) {
            base.WndProc(ref m);
            // Trap WM_NCHITTEST when the ALT key is down
            if (m.Msg == 0x84 && (Control.ModifierKeys == Keys.Alt)) {
                // Translate HTCLIENT to HTCAPTION
                if (m.Result == (IntPtr)1) m.Result = (IntPtr)2;
            }
        }
    

提交回复
热议问题