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.

Adam Wright
  • 48,938
  • 12
  • 131
  • 152
MetaGuru
  • 42,847
  • 67
  • 188
  • 294

2 Answers2

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);
    }
Phil Wright
  • 22,580
  • 14
  • 83
  • 137
  • 2
    Where to put that code? When I put it under InitializeCoponets it didn't work. I wan't even called once. – Hooch Sep 22 '11 at 22:36
  • 1
    Put at the form class. By the way, WM_NCHITTEST = 0x84 and HTTRANSPARENT = -1. It works!!! :D – Pedro77 Mar 13 '12 at 12:45
  • 1
    Curiously this didn't work for me in Win8 using a [layered](http://msdn.microsoft.com/en-us/library/ms997507.aspx) window: hovers would go through, but clicks would activate my window instead of going through. What worked instead was to [set WS_EX_TRANSPARENT](http://stackoverflow.com/a/2798294/33080). – Roman Starkov Feb 03 '13 at 05:08
  • 1
    Also not working for me, win10x64, C# Windows Forms project using .net 4.5. I'm not getting hover events, either, interestingly. – omJohn8372 Jan 16 '18 at 16:59
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.