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?
Asked
Active
Viewed 3,070 times
1
-
1There 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 Answers
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!
-
where does the error go??? did you add the `System.Runtime:InteropServices` directive? – cramopy Oct 10 '15 at 19:36
-
Have you ever run it? Please do. Hint: What is the type of the `params` variable (`var params = ...`)? – Dmitry Oct 10 '15 at 19:41
-
-
Nice try, but the code is wrong. The answer you linked to has the correct code. In the future, please don't copy and paste code (incorrectly or not) from other answers. Just flag the question as a duplicate. – Cody Gray - on strike Jul 09 '16 at 17:58
-