Pass-through mouse events to parent control

Yes. After a lot of searching, I found the article “Floating Controls, tooltip-style”, which uses WndProc to change the message from WM_NCHITTEST to HTTRANSPARENT, making the Control transparent to mouse events.

To achieve that, create a control inherited from Label and simply add the following code.

protected override void WndProc(ref Message m)
{
    const int WM_NCHITTEST = 0x0084;
    const int HTTRANSPARENT = (-1);

    if (m.Msg == WM_NCHITTEST)
    {
        m.Result = (IntPtr)HTTRANSPARENT;
    }
    else
    {
        base.WndProc(ref m);
    }
}

I have tested this in Visual Studio 2010 with .NET Framework 4 Client Profile.

Leave a Comment