Click through transparency for Visual C# Window Forms?
Asked Answered
D

2

14

I made a panel and set it to fill the screen, now I can see the windows under it but I want it to be click through, meaning they could click a file or see a tool tip of another object through the transparency.

RE: This may be too obvious, but have you tried sending the panel to the back by right clicking and choosing "Send to Back"?

I mean like the desktop or firefox, not something within my project.

Determination answered 21/9, 2008 at 21:21 Comment(0)
T
22

Creating a top level form that is transparent is very easy. Just make it fill the screen, or required area, and define it to have a TransparenyKey color and BackColor of the same value.

Getting it to ignore the mouse is simple enough, you just need to override the WndProc and tell the WM_HITTEST that all mouse positions are to be treated as transparent. Thus causing the mouse to interact with whatever happens to be underneath the window. Something like this...

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == (int)WM_NCHITTEST)
            m.Result = (IntPtr)HTTRANSPARENT;
        else
            base.WndProc(ref m);
    }
Tientiena answered 21/9, 2008 at 23:54 Comment(4)
Where to put that code? When I put it under InitializeCoponets it didn't work. I wan't even called once.Pacifier
Put at the form class. By the way, WM_NCHITTEST = 0x84 and HTTRANSPARENT = -1. It works!!! :DInexplicable
Curiously this didn't work for me in Win8 using a layered window: hovers would go through, but clicks would activate my window instead of going through. What worked instead was to set WS_EX_TRANSPARENT.Repatriate
Also not working for me, win10x64, C# Windows Forms project using .net 4.5. I'm not getting hover events, either, interestingly.Batten
S
0

A much simpler method that might work.

step 1.) click on the panel in (design)

step 2.) look in properties

step 3.) set Enabled to False

this allowed me to click past my panel to the one behind it.

Shew answered 17/10, 2022 at 22:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.