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 = 100;

[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> 
public void SetPenetrate()
{
    this.TopMost = true;
    SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
    SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
}

C#winform

3 条评论

  1. zgoxintice
    2024-11-14 03:17
    回复

    博主太厉害了!

  2. rengilklmf
    2024-09-23 04:34
    回复

    叼茂SEO.bfbikes.com

  3. 站元素主机
    2021-03-10 09:08
    回复

    赞一个 学习了

添加新评论