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

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

    It seems you found a solution to a problem with caused another problem that you're trying to solve. If I could suggest something simple, just a better solution to make a window drag-able:

    Add InteropServices to the using declarations:

    using System.Runtime.InteropServices;
    

    And for the code:

        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;
    
        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd,
                         int Msg, int wParam, int lParam);
        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();
    

    Then go to the form's MouseDown event and paste this:

            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
    

    Done.

提交回复
热议问题