WinForms equivalent of WPF's IsHitTestVisible

依然范特西╮ 提交于 2019-11-28 01:44:19

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 ); 
    }
}

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!