把窗体的formborderstyle设为formborderstyle.none
using system.runtime.interopservices;
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 = 0x2;
[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 canpenetrate()
{
uint intextemp = getwindowlong(this.handle, gwl_exstyle);
uint oldgwlex = setwindowlong(this.handle, gwl_exstyle, ws_ex_transparent | ws_ex_layered);
setlayeredwindowattributes(this.handle, 0, 100, lwa_alpha);
}
要时窗体恢复正常,只要执行以下语句:
this.formborderstyle = formborderstyle.none;
新闻热点
疑难解答