WinForms equivalent of WPF's IsHitTestVisible

前端 未结 2 1311
小蘑菇
小蘑菇 2020-12-04 01:27

I have a button override that has a Label as a child. I have MouseEnter and Leave events attached to the button control.

When the mouse enters the label the button\'

相关标签:
2条回答
  • 2020-12-04 01:58

    The short answer is that you cannot. Both the button and the label are in fact windows, so when the mouse leave one for the other, mouseenter and mouseleave events are generated.

    The real question is, why do you need a label on a button?

    0 讨论(0)
  • 2020-12-04 02:01

    Ran across this question while looking for other information and don't believe the accepted answer is really correct.

    You can extend the label and alter the hittest response in WndProc. Something along these lines:

    public class HTTransparentLabel : Label
    {
        private const int WM_NCHITTEST = 0x84; 
        private const int HTTRANSPARENT = -1; 
    
        protected override void WndProc(ref Message message) 
        { 
            if ( message.Msg == (int)WM_NCHITTEST ) 
                message.Result = (IntPtr)HTTRANSPARENT; 
            else 
                base.WndProc( ref message ); 
        }
    }
    
    0 讨论(0)
提交回复
热议问题