C# 毛玻璃 透明效果


using System.Runtime.InteropServices;
public struct Margins //邊距結構 { public int Left; public int Right; public int Top; public int Bottom; } [DllImport("dwmapi.dll", PreserveSig = false)]//引入Dll static extern void DwmExtendFrameIntoClientArea(IntPtr dwm, ref Margins margins);//Dll中的用法 [DllImport("dwmapi.dll", PreserveSig = false)]//引入Dll static extern bool DwmIsCompositionEnabled();//Dll中的用法 public Form1() { InitializeComponent(); this.Opacity = 0.95;//改變視窗透明度 } protected override void OnLoad(EventArgs e)//複寫OnLoad { Margins margins = new Margins() { }; margins.Right = margins.Left = margins.Top = margins.Bottom = -1; if (DwmIsCompositionEnabled())//檢查特效是否開啟 DwmExtendFrameIntoClientArea(this.Handle, ref margins);//使用Aero特效 base.OnLoad(e); } protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (DwmIsCompositionEnabled()) e.Graphics.Clear(Color.Black);//將視窗顏色填充為黑色(Aero中黑色為要用特效的區域) }

留言

這個網誌中的熱門文章

UVA 11321 Java