How to block double click in overridden WndProc function in Windows Forms?

后端 未结 5 1735
名媛妹妹
名媛妹妹 2021-01-13 20:00

I have a form created in Windows Forms which is draggable wherever I click. I made it by overriding WndProc function which in turn modifies each click as it was a title bar

5条回答
  •  無奈伤痛
    2021-01-13 20:42

    I've done the same as Jex which is working great.

    private const int WM_NCHITTEST = 0x84;
    private const int HTCLIENT = 0x1;
    private const int HTCAPTION = 0x2;
    private const int WM_LBUTTONDBLCLK = 0x00A3;
    
    protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_LBUTTONDBLCLK)
            {
                return;
            }
            switch (m.Msg)
            {
    
                case WM_NCHITTEST:      
                    base.WndProc(ref m);
                    if ((int)m.Result == HTCLIENT)
                        m.Result = (IntPtr)HTCAPTION;
                    return;
            }
            base.WndProc(ref m);
        }
    

提交回复
热议问题