Windows窗体:通过部分透明的always-on-top窗口传递点击次数

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

例

看到灰色吧? 这会阻止我在此刻输入标签框。

您可以通过将WS_EX_LAYEREDWS_EX_TRANSPARENT样式添加到其扩展样式来创建窗口,单击。 另外,为了使其始终位于顶部,将其TopMost设置为true并使其半透明使用合适的Opacity值:

 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); } } 

样本结果

在此处输入图像描述