zoukankan      html  css  js  c++  java
  • windows 10 透明毛玻璃,winform和wpf方法

    win10的透明毛玻璃,winform和wpf方法,win7、8不能用,只是win10
     public partial class Form1 : Form
        {
            [DllImport("user32.dll")]
            internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
    
            [StructLayout(LayoutKind.Sequential)]
            internal struct WindowCompositionAttributeData
            {
                public WindowCompositionAttribute Attribute;
                public IntPtr Data;
                public int SizeOfData;
            }
    
            internal enum WindowCompositionAttribute
            {
                WCA_ACCENT_POLICY = 19
            }
    
            internal enum AccentState
            {
                ACCENT_DISABLED = 0,
                ACCENT_ENABLE_GRADIENT = 1,
                ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
                ACCENT_ENABLE_BLURBEHIND = 3,
                ACCENT_INVALID_STATE = 4
            }
    
            [StructLayout(LayoutKind.Sequential)]
            internal struct AccentPolicy
            {
                public AccentState AccentState;
                public int AccentFlags;
                public int GradientColor;
                public int AnimationId;
            }
    
            internal void EnableBlur()
            {
                var accent = new AccentPolicy();
                var accentStructSize = Marshal.SizeOf(accent);
                accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
    
                var accentPtr = Marshal.AllocHGlobal(accentStructSize);
                Marshal.StructureToPtr(accent, accentPtr, false);
    
                var data = new WindowCompositionAttributeData();
                data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
                data.SizeOfData = accentStructSize;
                data.Data = accentPtr;
    
                SetWindowCompositionAttribute(this.Handle, ref data);
    
                Marshal.FreeHGlobal(accentPtr);
            }
    ...................
    ...................
    private void Form1_Load(object sender, EventArgs e)
            {
                EnableBlur();
            }
    
    窗体背景设置比如Red,然后TransparencyKey=Red,就有行了。
    
    如果使用WPF,修改:
    internal void EnableBlur()
    {
        var windowHelper = new WindowInteropHelper(this);
        ......
        ......
        SetWindowCompositionAttribute(windowHelper.Handle, ref data);
        ......
    }
    
  • 相关阅读:
    int k=0;k=k++;结果等于0,为什么?
    CentOS在无法连接外网的服务器上安装软件(以docker为例)
    docker搭建 elasticsearch 集群
    docker容器之间进行网络通信
    Kafka集群搭建
    Zookeeper集群搭建及常用命令
    SpringBoot将Swagger2文档导出为markdown或html
    Linux(CentOS7)虚拟机修改 NAT模式固定IP
    Linux Maven私服(Nexus)搭建
    Linux配置开机自启动
  • 原文地址:https://www.cnblogs.com/qiaoke/p/8395106.html
Copyright © 2011-2022 走看看