Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows窗体:通过部分透明的始终位于顶部的窗口传递单击_C#_.net_Winforms_Transparent - Fatal编程技术网

C# Windows窗体:通过部分透明的始终位于顶部的窗口传递单击

C# Windows窗体:通过部分透明的始终位于顶部的窗口传递单击,c#,.net,winforms,transparent,C#,.net,Winforms,Transparent,我正在设计一个始终在屏幕上的窗口,大约20%不透明。它被设计成一种状态窗口,所以它总是在顶部,但我希望人们能够通过窗口点击下面的任何其他应用程序。这是一个不透明的窗口,在我现在打字时,它位于这篇文章的顶部: 看到那个灰色的酒吧了吗?这将阻止我现在在标记框中键入内容。您可以创建一个窗口,通过在扩展样式中添加和样式来单击。此外,要使其始终位于顶部,请将其设置为true,并使用合适的值使其半透明: 样本结果 winforms不可能。您有任何证据支持该答案吗?我觉得很难相信…相信它。我的“证据”是十多

我正在设计一个始终在屏幕上的窗口,大约20%不透明。它被设计成一种状态窗口,所以它总是在顶部,但我希望人们能够通过窗口点击下面的任何其他应用程序。这是一个不透明的窗口,在我现在打字时,它位于这篇文章的顶部:


看到那个灰色的酒吧了吗?这将阻止我现在在标记框中键入内容。

您可以创建一个窗口,通过在扩展样式中添加和样式来单击。此外,要使其始终位于顶部,请将其设置为
true
,并使用合适的值使其半透明:

样本结果


winforms不可能。您有任何证据支持该答案吗?我觉得很难相信…相信它。我的“证据”是十多年来使用win表单的经验。@rory.ap我认为发布的答案正是OP想要的。我是否遗漏了问题的某些部分?它在Windows7上运行。我的观点是正确的。太酷了!您只需重写CreateParams并使用P/Invoke设置ExStyle即可。我尝试了此解决方案,但在单击窗口时发生了错误nothing@BruceStackOverFlow单击将传递到背景窗口。我使用ubuntu和mono,这似乎不起作用@BruceStackOverFlow它是Windows上的WinForms(.NET),而不是Linux上的mono。
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.Opacity = 0.5;
        this.TopMost = true;
    }
    [DllImport("user32.dll", SetLastError = true)]
    static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    [DllImport("user32.dll")]
    static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
    const int GWL_EXSTYLE = -20;
    const int WS_EX_LAYERED = 0x80000;
    const int WS_EX_TRANSPARENT = 0x20;
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        var style = GetWindowLong(this.Handle, GWL_EXSTYLE);
        SetWindowLong(this.Handle,GWL_EXSTYLE , style | WS_EX_LAYERED | WS_EX_TRANSPARENT);
    }
}