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

后端 未结 5 1738
名媛妹妹
名媛妹妹 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:29

    If you just want to stop the double click from having it's default behavior in the window for which you've overridden the WndProc then intercept the WM_LBUTTONDBLCLK message

    private const int WM_LBUTTONDBLCLK = 0x0203;
    
    ...
    
    protected override void WndProc(ref Message message) {
      if (message.Msg == WM_LBUTTONDBLCLK) {
        return;
      }
    
      base.WndProc(ref message);
    
      if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
        message.Result = (IntPtr)HTCAPTION;
    }
    

提交回复
热议问题