C# WinForm實現(xiàn)Win7 Aero透明效果代碼
在Vista系統(tǒng)之后,微軟為窗體程序提供了Aero磨砂的效果,如下圖。那么用C#如何來實現(xiàn)這種磨砂效果呢?
背景為我的桌面
那先上代碼吧:
[StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int Left; public int Right; public int Top; public int Bottom; } [DllImport("dwmapi.dll", PreserveSig = false)] static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins); [DllImport("dwmapi.dll", PreserveSig = false)] static extern bool DwmIsCompositionEnabled(); public Form1() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { if (DwmIsCompositionEnabled()) { MARGINS margins = new MARGINS(); margins.Right = margins.Left = margins.Top = margins.Bottom = this.Width + this.Height; DwmExtendFrameIntoClientArea(this.Handle, ref margins); } base.OnLoad(e); } protected override void OnPaintBackground(PaintEventArgs e) { base.OnPaintBackground(e); if (DwmIsCompositionEnabled()) { e.Graphics.Clear(Color.Black); } }
這中效果的實現(xiàn)主要是調用了系統(tǒng)的dwmapi.dll。
dwmapi.dll是Microsoft Desktop Window Manager API(桌面窗口管理器DWM 的公用界面)的動態(tài)鏈接庫,正常文件,主要用作桌面效果的api。DWM 是一種新界面,在除 Windows Vista Home Basic 之外的所有 Windows Vista 版本中均提供 DWM 界面。
所以這種效果只能在Vista之后的系統(tǒng)中使用。
相關文章
c#只讀字段和常量的區(qū)別,以及靜態(tài)構造函數(shù)的使用實例
這篇文章主要介紹了c#只讀字段和常量的區(qū)別,以及靜態(tài)構造函數(shù)的使用實例,有需要的朋友可以參考一下2013-12-12