在Vista系統之後,微軟為窗體程序提供了Aero磨砂的效果,如下圖。那麼用C#如
何來實現這種磨砂效果呢?
代碼:
System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Text;
System.Windows.Forms;
System.Reflection;
System.Runtime.InteropServices;
WindowsFormsApplication1
{
partial Form1 : Form
{
[StructLayout(LayoutKind.Sequential)]
MARGINS
{
Left;
Right;
Top;
Bottom;
}
[DllImport("", PreserveSig = )]
DwmExtendFrameIntoClientArea(IntPtr hwnd, MARGINS
margins);
[DllImport("", PreserveSig = )]
DwmIsCompositionEnabled();
OnLoad(EventArgs e)
{
(DwmIsCompositionEnabled())
{
MARGINS margins = MARGINS();
margins.Right = margins.Left = margins.Top = margins.Bottom =
.Width + .Height;
DwmExtendFrameIntoClientArea(.Handle, margins);
}
.OnLoad(e);
}
OnPaintBackground(PaintEventArgs e)
{
.OnPaintBackground(e);
(DwmIsCompositionEnabled())
{
e.Graphics.Clear(Color.Black);
}
}
Form1()
{
InitializeComponent();
}
}
}
這中效果的實現主要是調用了系統的dwmapi.dll。
dwmapi.dll是Microsoft Desktop Window Manager API(桌面窗口管理器DWM 的公用界面)的動態鏈接庫,正常文件,主要用作桌面效果的api。
DWM 是一種新界面,在除 Windows Vista Home Basic 之外的所有 Windows Vista 版本中均提供 DWM 界面。所以這種效果只能在Vista之後的系統中使用。