• [开发笔记]-实现winform半透明毛玻璃效果


    亲测win7下可用,win8下由于系统不支持Aero效果,所以效果不是半透明的。

    代码:

    博客园插入不了代码了。。。。。

    public partial class Form1 : Form
        {
            int en;
    
            public struct MARGINS
            {
                public int m_Left;
                public int m_Right;
                public int m_Top;
                public int m_Buttom;
            };
    
            [DllImport("dwmapi.dll")]
            private static extern void DwmIsCompositionEnabled(ref int enabledptr);
            [DllImport("dwmapi.dll")]
            private static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margin);
    
    
    
    
            public Form1()
            {
                InitializeComponent();
                en = 0;
                MARGINS mg = new MARGINS(); //定义透明扩展区域的大小,这里全部-1,即全部透明
                mg.m_Buttom = -1;
                mg.m_Left = -1;
                mg.m_Right = -1;
                mg.m_Top = -1;
    
                //判断是否Vista及以上的系统
                if (System.Environment.OSVersion.Version.Major >= 6)
                {
                    DwmIsCompositionEnabled(ref en);    //检测Aero是否为打开
                    if (en > 0)
                    {
                        DwmExtendFrameIntoClientArea(this.Handle, ref mg);   //透明
                    }
                    
                }
               
                this.Paint += new PaintEventHandler(Form1_Paint);
    
            }
    
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                if (en > 0)
                {
                    Graphics g = e.Graphics;
                    SolidBrush bsh = new SolidBrush(Color.Black);
                    g.FillRectangle(bsh, this.ClientRectangle);
                    bsh.Dispose();
                }
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
        }

    win7下的效果为半透明毛玻璃效果,win8下的效果:

    转载请注明出处。

  • 相关阅读:
    物流与仓库
    测试使用
    禅修的升级
    《引爆点 马尔科姆 格拉德威尔》读书笔记总结----《创业必读书第20本》--创业第三关做好业务:3,如何做好营销和增长第4本
    shell
    Vue中常用的方法记录
    前端工程化3-tapable
    Browser上传文件到华为云/七牛云 详细步骤
    immutable
    shell利用叮叮发送消息
  • 原文地址:https://www.cnblogs.com/babycool/p/3724842.html
Copyright © 2020-2023  润新知