#region 窗体鼠标穿透
private const uint WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int GWL_STYLE = (-16);
private const int GWL_EXSTYLE = (-20);
private const int LWA_ALPHA = 0;
[DllImport("user32", EntryPoint = "SetWindowLong")]
private static extern uint SetWindowLong(
IntPtr hwnd,
int nIndex,
uint dwNewLong
);
[DllImport("user32", EntryPoint = "GetWindowLong")]
private static extern uint GetWindowLong(
IntPtr hwnd,
int nIndex
);
[DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
private static extern int SetLayeredWindowAttributes(
IntPtr hwnd,
int crKey,
int bAlpha,
int dwFlags
);
/// <summary>
/// 声明委托类
/// </summary>
/// <param name="MsgStr"></param>
C#-窗体鼠标穿透
最新推荐文章于 2025-07-24 11:31:15 发布
本文档介绍如何在C#中实现窗体的鼠标穿透效果,通过设置窗体的WS_EX_TRANSPARENT和WS_EX_LAYERED风格,并使用SetWindowLong、GetWindowLong和SetLayeredWindowAttributes等API函数,使窗体变得透明并允许鼠标穿透。

最低0.47元/天 解锁文章
392

被折叠的 条评论
为什么被折叠?



