博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# WinForm实现Windows 7 Aero磨砂玻璃效果
阅读量:4579 次
发布时间:2019-06-09

本文共 1823 字,大约阅读时间需要 6 分钟。

代码

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Reflection;using System.Runtime.InteropServices;//引用DLL申明namespace WindowsFormsApplication1{    public partial class Form1 : Form    {        //DLL申明        [StructLayout(LayoutKind.Sequential)]        public struct MARGINS        {            public int Left;            public int Right;            public int Top;            public int Bottom;        }        //DLL申明        [DllImport("dwmapi.dll", PreserveSig = false)]        static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS        margins);        //DLL申明        [DllImport("dwmapi.dll", PreserveSig = false)]        static extern bool DwmIsCompositionEnabled();        //直接添加代码        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);            }        }        public Form1()        {            InitializeComponent();        }    }}

这中效果的实现主要是调用了系统的dwmapi.dll。

dwmapi.dll是Microsoft Desktop Window Manager API(桌面窗口管理器DWM 的公用界面)的动态链接库,正常文件,主要用作桌面效果的api。

DWM 是一种新界面,在除 Windows Vista Home Basic 之外的所有 Windows Vista 版本中均提供 DWM 界面。所以这种效果只能在Vista之后的系统中使用。

转载于:https://www.cnblogs.com/cnki/p/8689008.html

你可能感兴趣的文章
MapRedece(单表关联)
查看>>
蒲公英App开发之检测新版本
查看>>
【安卓基础】倒计时按钮封装(验证码倒计时按钮)
查看>>
configparser模块
查看>>
SelectQueryBuilder的用法
查看>>
android的用户定位(一)
查看>>
creat-react-app搭建的项目中按需引入antd以及配置Less和如何修改antd的主题色
查看>>
IIS安装
查看>>
html块级元素和行级元素的区别和使用
查看>>
for循环嵌套
查看>>
寒冬夜行人
查看>>
poj1151 Atlantis
查看>>
HTML页面之间的参数传递
查看>>
java面试题集锦
查看>>
scikit-learn:4.2.3. Text feature extraction
查看>>
Spring Security构建Rest服务-0800-Spring Security图片验证码
查看>>
AE待整理
查看>>
java8中规范的四大函数式接口
查看>>
宝塔apache配置
查看>>
shell脚本中使用nohup执行命令不生效
查看>>