创建一个叫AeroGlass.cs 的类,代码如下:
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
[StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
public MARGINS(Thickness t)
{
Left = (int)t.Left;
Right = (int)t.Right;
Top = (int)t.Top;
Bottom = (int)t.Bottom;
}
public int Left;
public int Right;
public int Top;
public int Bottom;
}
public class GlassHelper
{
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern void DwmExtendFrameIntoClientArea(
IntPtr hWnd, ref MARGINS pMarInset);
[DllImport("dwmapi.dll", PreserveSig = false)]
static extern bool DwmIsCompositionEnabled();
public static bool ExtendGlassFrame(Window window, Thickness margin)
{
if (!DwmIsCompositionEnabled())
return false;
IntPtr hwnd = new WindowInteropHelper(win

本文介绍如何在WPF应用中通过几行代码实现窗体的Aero Glass毛玻璃效果。通过创建AeroGlass.cs类,并在OnSourceInitialized事件中调用GlassHelper.ExtendGlassFrame方法,可以轻松为窗体添加美观的毛玻璃视觉效果。完整代码及下载链接已提供。
314

被折叠的 条评论
为什么被折叠?



