VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > 汇编语言 >
  • C#教程之用 C# Winform做出全透明的磨砂玻璃窗体效

首先, 调用系统 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);
}
}


相关教程