ToolStrip sometimes not responding to a mouse click

后端 未结 5 845
野的像风
野的像风 2020-12-06 17:49

I have a .NET 2.0 WinForms application with a ToolStrip on my main form. Sometimes, the ToolStrip icons don\'t respond to the first mouse click, so I have to click the icon

5条回答
  •  孤城傲影
    2020-12-06 18:20

    Here is the implementation for @Doc Brown's solution:

    public class ToolStripX : ToolStrip
    {
        private const int WM_MOUSEACTIVATE = 0x0021;
        private const int MA_ACTIVATEANDEAT = 2;
        private const int MA_ACTIVATE = 1;
    
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
    
            if (m.Msg == WM_MOUSEACTIVATE &&
                m.Result == (IntPtr)MA_ACTIVATEANDEAT)
            {
                m.Result = (IntPtr)MA_ACTIVATE;
            }
        }
    }
    

提交回复
热议问题