获取窗口的强调色

时间:2015-10-10 19:04:46

标签: c# winforms

如何从窗口获取强调色?因为我想让ToolStrip与窗口的强调颜色具有相同的颜色 我在Google上查了一下,所有这些都是一些Windows Phone的东西或者没有工作 有人能帮帮我吗?

1 个答案:

答案 0 :(得分:2)

您可以使用以下代码:

internal static class NativeMethods
{
    [DllImport("dwmapi.dll", EntryPoint="#127")]
    internal static extern void DwmGetColorizationParameters(ref DWMCOLORIZATIONcolors colors);
}

public struct DWMCOLORIZATIONcolors
{
    public uint ColorizationColor, 
        ColorizationAfterglow, 
        ColorizationColorBalance, 
        ColorizationAfterglowBalance, 
        ColorizationBlurBalance, 
        ColorizationGlassReflectionIntensity, 
        ColorizationOpaqueBlend;
}

private static Color GetWindowColorizationColor(bool opaque)
{
    var colors = NativeMethods.DwmGetColorizationParameters();

    return Color.FromArgb((byte)(opaque ? 255 : colors.ColorizationColor >> 24),
        (byte)(colors.ColorizationColor >> 16), 
        (byte)(colors.ColorizationColor >> 8), 
        (byte)colors.ColorizationColor);
}

如果您还希望在程序运行时更改颜色,请参阅this发布!