C# 分别在windows form和wpf中实现windows 7 玻璃(areo)效果
2011-09-27 13:49
579 查看
在windows7中大量使用了玻璃效果(也就是说Areo效果)感觉非常漂亮。平时自己做一些小东西也很想要这个效果,于是琢磨了一下。
注:使用此API可以实现很多windows 7的特效(如:jumplist,areo,任务栏图标显示任务进度,等等。。。)
首先在程序中引入上面的API,然后只需要把我们的Form窗体继承自Microsoft.WindowsAPICodePack.Shell.GlassForm就可以了。
效果:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202004/06/13175964013da341b03a1cb5aaca08d8.gif)
2、在wpf程序中实现玻璃效果
这里我们同样用系统提供的API来实现
效果和上面的图片一致。
1、在windows form程序中实现玻璃效果
这里要用到微软提供的Windows 7 API Code Pack注:使用此API可以实现很多windows 7的特效(如:jumplist,areo,任务栏图标显示任务进度,等等。。。)
首先在程序中引入上面的API,然后只需要把我们的Form窗体继承自Microsoft.WindowsAPICodePack.Shell.GlassForm就可以了。
public partial class AeroForm : GlassForm
效果:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202004/06/13175964013da341b03a1cb5aaca08d8.gif)
2、在wpf程序中实现玻璃效果
这里我们同样用系统提供的API来实现
/// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { this.Background = Brushes.Transparent; ExtendAeroGlass(this); } [StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; }; [DllImport("DwmApi.dll")] public static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref MARGINS pMarInset); private void ExtendAeroGlass(Window window) { try { // 为WPF程序获取窗口句柄 IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent; // 设置Margins MARGINS margins = new MARGINS(); // 扩展Aero Glass margins.cxLeftWidth = -1; margins.cxRightWidth = -1; margins.cyTopHeight = -1; margins.cyBottomHeight = -1; int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); if (hr < 0) { MessageBox.Show("DwmExtendFrameIntoClientArea Failed"); } } catch (DllNotFoundException) { Application.Current.MainWindow.Background = Brushes.White; } } }
效果和上面的图片一致。
相关文章推荐
- 在WPF中实现玻璃模糊效果
- WPF实现毛玻璃效果
- C#实现毛玻璃效果
- Qt实现areo毛玻璃效果的类,以及使用方法:
- win7下 窗体玻璃效果的实现和WindowStyle None模式下的移动 wpf
- C# WinForm实现Windows 7 Aero磨砂玻璃效果
- Android相册效果(使用C#和Java分别实现)
- WPF实现毛玻璃效果
- C#编写Windows服务程序 (服务端),client使用 消息队列 实现淘宝 订单全链路效果
- wpf 实现实时毛玻璃(live blur)效果
- WPF 学习笔记 Areo玻璃效果的接触
- Android下拉列表(Spinner)效果(使用C#和Java分别实现)
- WPF 几行代码实现窗体毛玻璃效果(Aero Glass)
- WPF 几行代码实现窗体毛玻璃效果(Aero Glass)
- 基于C#实现的仿windows左侧伸缩菜单效果
- C#编写Windows服务程序 (服务端),客户端使用 消息队列 实现淘宝 订单全链路效果
- 折腾了一早上的C# WPF ListView+Grid 实现图片+文字 自动换行排列 类似Windows资源管理器效果
- C# 实现截屏效果
- iOS 实现毛玻璃效果
- 不同平台(mac、windows—wpf、web、ios、android)下实现页面的转场动画