WPF 几行代码实现窗体毛玻璃效果(Aero Glass)
来源:互联网 发布:linux自定义命令 编辑:程序博客网 时间:2024/05/20 17:40
创建一个叫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(window).Handle; if (hwnd == IntPtr.Zero) throw new InvalidOperationException( "The Window must be shown before extending glass."); // Set the background to transparent from both the WPF and Win32 perspectives window.Background = Brushes.Transparent; HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent; MARGINS margins = new MARGINS(margin); DwmExtendFrameIntoClientArea(hwnd, ref margins); return true; }}
把这段代码加到主窗体就可以了!
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
GlassHelper.ExtendGlassFrame(this, new Thickness(-1));
}
完整代码下载:http://www.dengfengsoft.com/docs/AeroGlass.zip
- WPF 几行代码实现窗体毛玻璃效果(Aero Glass)
- 透明窗体 使用DWM实现Aero Glass效果
- C# Winform 窗体美化(七、Win7 Aero 毛玻璃效果)
- 使用DWM实现Aero Glass效果
- 使用DWM实现Aero Glass效果
- MFC--使用DWM实现Aero Glass效果
- 使用DWM实现Aero Glass效果 .
- 使用DWM实现Aero Glass效果
- 使用DWM实现Aero Glass效果
- 使用DWM实现Aero Glass效果
- Delphi窗体GlassFrame实现在win7下的Aero Glass效果
- C#迅雷七窗体特效,使用DWM实现Aero Glass效果
- WPF实现毛玻璃效果
- 关于AERO glass效果 DwmEnableComposition
- Windows 7 扩展玻璃效果(Aero Glass)
- C#实现具有Aero效果的窗体
- C#实现具有Aero效果的窗体
- C#实现具有Aero效果的窗体
- 文件操作
- Io包下的其他对象
- Java流与文件操作
- Qt+VS2005 LNK 2019 LNK2001 问题解决方案
- IFrame自适应高度
- WPF 几行代码实现窗体毛玻璃效果(Aero Glass)
- 缓冲字符流
- java并发编程--线程池初步
- 字节流
- (转)android面试题
- Cannot find the class file for javax.servlet.ServletContext.
- 怎样花两年时间去面试一个人-转自刘未鹏的博客
- 记win7下 硬盘安装ubuntu11.04
- 20 种提升网页速度的技巧