您可以使用“一对”调用,并且在启用“自动从我的背景中选择强调色”时也可以使用
public static Color GetWindowsAccentColor()
{
WinApi.DWMCOLORIZATIONcolors colors = new WinApi.DWMCOLORIZATIONcolors();
WinApi.DwmGetColorizationParameters(ref colors);
//get the theme --> only if Windows 10 or newer
if (OS.IsWindows10orGreater())
return ParseColor((int)colors.ColorizationColor);
else
return Color.CadetBlue;
}
private static Color ParseColor(Int32 color)
{
var opaque = true;
return Color.FromArgb((byte)(opaque ? 255 : (color >> 24) & 0xff),
(byte)((color >> 16) & 0xff),
(byte)((color >> 8) & 0xff),
(byte)(color) & 0xff);
}
拥有 WinApi 类:
public struct DWMCOLORIZATIONcolors
{
public uint ColorizationColor,
ColorizationAfterglow,
ColorizationColorBalance,
ColorizationAfterglowBalance,
ColorizationBlurBalance,
ColorizationGlassReflectionIntensity,
ColorizationOpaqueBlend;
}
[DllImport("dwmapi.dll", EntryPoint = "#127")]
public static extern void DwmGetColorizationParameters(ref DWMCOLORIZATIONcolors colors);
和操作系统类:
public static bool IsWindows10orGreater()
{
if (WindowsVersion() >= 10)
return true;
else
return false;
}
public static int WindowsVersion()
{
//for .Net4.8 and Minor
int result = 10;
var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion");
string[] productName = reg.GetValue("ProductName").ToString().Split((char)32);
int.TryParse(productName[1], out result);
return result;
//fixed .Net6
//return System.Environment.OSVersion.Version.Major;
}
希望这会有所帮助
安杰洛