• 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);
        ......
    }
    
  • 相关阅读:
    CMS网站 中最好用的!
    成为优秀设计师的十大条件
    网站变色(黑白)!
    设计师必知的18种服装风格
    HDFS核心类FileSystem的使用
    Hadoop的伪分布式安装和部署的流程
    初学MapReduce离线计算(eclipse实现)
    hdfs的客户端读写流程以及namenode,secondarynamenode,checkpoint原理
    hadoop常用的操作指令
    TableLayoutPanel&SplitContainer 布局
  • 原文地址:https://www.cnblogs.com/qiaoke/p/8395106.html
Copyright © 2020-2023  润新知