当前位置: 移动技术网 > IT编程>开发语言>c# > 用 C# Winform做出全透明的磨砂玻璃窗体效果代码

用 C# Winform做出全透明的磨砂玻璃窗体效果代码

2019年07月18日  | 移动技术网IT编程  | 我要评论
首先, 调用系统 api, 这里如果要引用神马的, 就不一一列出了, 大家自己引用一下.
复制代码 代码如下:

[structlayout(layoutkind.sequential)]
public struct margins
{
public int left;
public int right;
public int top;
public int bottom;
}

[dllimport("dwmapi.dll", preservesig = false)]
public static extern void dwmextendframeintoclientarea
(intptr hwnd, ref margins margins);

[dllimport("dwmapi.dll", preservesig = false)]
public static extern bool dwmiscompositionenabled();

然后重写两个事件:
复制代码 代码如下:

protected override void onload(eventargs e)
{
if (dwmiscompositionenabled())
{
margins margin = new margins();
margin.right = margin.left = margin.bottom = margin.top = -1;
dwmextendframeintoclientarea(this.handle, ref margin);
}
base.onload(e);
}

protected override void onpaintbackground(painteventargs e)
{
base.onpaintbackground(e);
if (dwmiscompositionenabled())
{
e.graphics.clear(color.black);
}
}

最后.. 木有了, f5 运行吧~

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网