C# console get Windows 10 Accent Color

我的未来我决定 提交于 2020-07-30 03:38:05

问题


Is there a way in .Net Core 2.X to read the Selected Windows 10 Accent Color in a Console Application.

Most of the solution i found are UWP or WPF apps.

Too show you wich color I mean, here is a picture of it:


回答1:


HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ - Stores all decoration colors. So if app launched with rights to HKEY_CURRENT_USER you can read or change "AccentColor" property (and others in directory) or change the color code in hexadecimal notation on your own.

To get access to windows registry you need to install package: https://www.nuget.org/packages/Microsoft.Windows.Compatibility/

Here info about package: https://docs.microsoft.com/en-us/dotnet/core/porting/windows-compat-pack/




回答2:


Starting with .NET Core 3.0 it is also possible to call UWP APIs from non UWP apps with the help of Microsoft.Windows.SDK.Contracts package.

So we can use UWP API to get accent color from .NET Core console app using:

var uiSettings = new UISettings();
var accentColor = uiSettings.GetColorValue(UIColorType.Accent);

The returned color is of type Windows.UI.Color, but can easily converted into for example System.Drawing.Color

Color.FromArgb(accentColor.A, accentColor.R, accentColor.G, accentColor.B);


来源:https://stackoverflow.com/questions/50840395/c-sharp-console-get-windows-10-accent-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!