单击 Visual C# 窗口窗体的透明度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/112224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 14:20:53  来源:igfitidea点击:

Click through transparency for Visual C# Window Forms?

提问by MetaGuru

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"?

RE:这可能太明显了,但是您是否尝试通过右键单击并选择“Send to Back”将面板发送到后面?

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

我的意思是像桌面或火狐一样,而不是我的项目中的东西。

采纳答案by Phil Wright

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.

创建透明的顶级表单非常容易。只需让它填满屏幕或所需区域,并将其定义为具有相同值的 TransparenyKey 颜色和 BackColor。

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...

让它忽略鼠标很简单,您只需要覆盖 WndProc 并告诉 WM_HITTEST 所有鼠标位置都将被视为透明。从而导致鼠标与窗口下方的任何东西进行交互。像这样的东西...

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == (int)WM_NCHITTEST)
            m.Result = (IntPtr)HTTRANSPARENT;
        else
            base.WndProc(ref m);
    }