如何获得Windows 10的配色?

master_ruko

我正在寻找一种获取Windows 10根据背景图像自动选择的颜色的方法,如下所示。

在此处输入图片说明

我尝试搜寻,发现

var color = (Color)this.Resources["SystemAccentColor"];

var color = (Color)Application.Current.Resources["SystemAccentColor"];

但两者都是例外

System.Exception
  HResult=0x8000FFFF
  Message=Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

诺鲁尔

在此代码中,您将仅获得十六进制颜色。Application.Current.Resources["SystemAccentColor"]您必须将其转换为可用的颜色格式,这是解决方案。

        var color = Application.Current.Resources["SystemAccentColor"];
        btnTest.Background = GetColorFromHex(color.ToString());

这是转换功能

public static SolidColorBrush GetColorFromHex(string hexaColor)
        {
            return new SolidColorBrush(
                Color.FromArgb(
                  Convert.ToByte(hexaColor.Substring(1, 2), 16),
                    Convert.ToByte(hexaColor.Substring(3, 2), 16),
                    Convert.ToByte(hexaColor.Substring(5, 2), 16),
                    Convert.ToByte(hexaColor.Substring(7, 2), 16)
                )
            );
        }

希望这可以帮助,

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何获得Windows 10 1809而非1903?

如何获得对Windows 10的完全访问权限?

如何获得Windows版本-如“ Windows 10,版本1607”?

如何在Windows 10下重新获得对目录的访问

如何获得Windows 10长期服务分支(LTSB)?

如何在Windows 10中获得Window Switcher功能

我如何获得Windows 10来识别蓝牙设备

如何在Windows 10中获得终端大小(使用PHP)

如何在Windows 10上重新获得启动超级按钮?

如何获得游戏控制器名称(Windows 10 / C ++)

如何在 Windows 10 上获得 g++ 7+?

如何获得在 Windows 10 中运行 Python 代码的权限

如何获得特定的Windows 10版本?

如何从Windows 2000备份配色方案?

如何在MS Flow或Logic Apps中获得配色方案?

获取Android系统配色(Android 10系统配色)

如何获得Windows 7串行密钥(升级到Windows 10后)?

如何确定macOS 10.14的配色?

如何找到网站的配色方案

如何更改Bootstrap的配色方案

如何获得Windows 10周年更新中的Synaptics扩展?

如何在Electron应用程序中获得Windows 10的主要颜色?

如何获得Windows 10以4K分辨率绘制1080p?

如何在Windows 10上获得模糊的半透明QML窗口(类似于Fluent Design准则)?

如何获得在Windows 10上为Anaconda3安装软件包的权限?

如何在Windows 10上重新获得Win + R历史记录?

您如何获得一个程序以显示在Windows 10搜索字段中?

在VS代码上使用鼠尾草时,如何获得python配色方案?

无法更改Windows 10背景-获得黑屏