How do I change the color of the .NET / Forms application in the Windows Aero taskbar?
There is no documented API. Microsoft has created the toolbar colors in Windows Aero to be changed by the user and not by the application.
However, there is the DwmSetColorizationParameters
API, without documentation. The recommendation is to use it however test the application on different versions of Windows, to see if the compatibility is 100%, otherwise you will have to filter the OS or not use it.
If you need OS validation, you may be able to use System.Environment.OSVersion
for i Identify the Windows version .
Second SOen users, it is compatible with Windows 7, but you need to test with subsequent SPs and updates.
The ready class looks like this:
using System;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
class DwmManager
{
private struct DWM_COLORIZATION_PARAMS
{
public uint clrColor;
public uint clrAfterGlow;
public uint nIntensity;
public uint clrAfterGlowBalance;
public uint clrBlurBalance;
public uint clrGlassReflectionIntensity;
public bool fOpaque;
}
[DllImport("dwmapi.dll", EntryPoint = "#127", PreserveSig = false)]
private static extern void DwmGetColorizationParameters(out DWM_COLORIZATION_PARAMS parameters);
[DllImport("dwmapi.dll", EntryPoint = "#131", PreserveSig = false)]
private static extern void DwmSetColorizationParameters(ref DWM_COLORIZATION_PARAMS parameters,
bool unknown);
// Helper method to convert from a Win32 BGRA-format color to a .NET color.
private static Color BgraToColor(uint color)
{
return Color.FromArgb(Int32.Parse(color.ToString("X"), NumberStyles.HexNumber));
}
// Helper method to convert from a .NET color to a Win32 BGRA-format color.
private static uint ColorToBgra(Color color)
{
return (uint)(color.B | (color.G << 8) | (color.R << 16) | (color.A << 24));
}
// Gets or sets the current color used for DWM glass, based on the user's color scheme.
public static Color ColorizationColor
{
get
{
// Call the DwmGetColorizationParameters function to fill in our structure.
DWM_COLORIZATION_PARAMS parameters;
DwmGetColorizationParameters(out parameters);
// Convert the colorization color to a .NET color and return it.
return BgraToColor(parameters.clrColor);
}
set
{
// Retrieve the current colorization parameters, just like we did above.
DWM_COLORIZATION_PARAMS parameters;
DwmGetColorizationParameters(out parameters);
// Then modify the colorization color.
// Note that the other parameters are left untouched, so they will stay the same.
// You can also modify these; that is left as an exercise.
parameters.clrColor = ColorToBgra(value);
// Call the DwmSetColorizationParameters to make the change take effect.
DwmSetColorizationParameters(ref parameters, false);
}
}
}
Once added to the project, just manipulate ColorizationColor
.
It's important to note that DWM Composition is supported by the OS and is enabled before performing any of these functions. To do this, you need this function:
[DllImport("dwmapi.dll")]
private static extern int DwmIsCompositionEnabled(ref bool pfEnabled);