1

How to get the accent color from window? Because I want to make the ToolStrip have the same color as accent color of window.
I searched it up on Google and all of them were some Windows Phone stuff or were not working.
Can someone help me please?

Dmitry
  • 13,797
  • 6
  • 32
  • 48
BakonBot
  • 55
  • 2
  • 8
  • 1
    There is no such term in WinForms. Take a look at the [SystemColors](https://msdn.microsoft.com/en-us/library/system.drawing.systemcolors(v=vs.110).aspx) class for available system colors. – Dmitry Oct 10 '15 at 19:20
  • I didn't mean that. I meant this. Heres Imgur link: http://imgur.com/XERleXu – BakonBot Oct 10 '15 at 19:23
  • Try this: [Retrieving Windows 8 Theme Colours](https://www.quppa.net/blog/2013/01/02/retrieving-windows-8-theme-colours/). – Dmitry Oct 10 '15 at 19:36
  • There still is no such thing as an accent color in Winforms. The Color of the title bar is determined by the system color scheme; the rest is all up to you. – TaW Oct 12 '15 at 16:11

1 Answers1

2

You can use the following code:

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);
}

If you also wanna update the color when it gets changed while your program is running please see this post!

Community
  • 1
  • 1
cramopy
  • 3,459
  • 6
  • 28
  • 42