首先, 调用系统 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 运行吧~

以上就是【用 C# Winform做出全透明的磨砂玻璃窗体效果代码】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)
发表我的评论

最新评论

  1. 暂无评论