1

Is there a way in C# to retrieve the current titlebar color?

I have a panel that sits directly under the titlebar (with shortcut icons) and it would be nice if it was the same color.

EDIT:

I just want the titlebar to match the area imidiately below it so it is all the same colour. The way it currently looks is two distinct shades of grey.

enter image description here

damichab
  • 162
  • 10
  • Are you asking about the (legacy) Win32 Active Titlebar color - or the Windows Vista DWM color? – Dai Apr 25 '23 at 01:52
  • Not sure. I just want to match the current colour, whatever it may be or set to, to a panel under the title. SystemColors.Control is too dark and SystemColors.Menu is too light. – damichab Apr 25 '23 at 01:55

1 Answers1

0

Is there a way in C# to retrieve the current titlebar color?

If you're asking about the old Win32 COLOR_ACTIVECAPTION color then in .NET Framework and .NET 5+ (and maybe .NET Core?) you can use System.Drawing.SystemColors.ActiveCaption - if you're drawing text on top of that then use ActiveCaptionText.

If you're after the DWM color then you'll need to use DwmGetColorizationColor:

internal static class NativeMethods
{
    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern void DwmGetColorizationColor( out UInt32 colorizationColor, [MarshalAs(UnmanagedType.Bool)] out Boolean colorizationOpaqueBlend );
}

(PreserveSig = false is what allows this to be void so we don't need to faff around with parsing HRESULT in C#)

You'll need to bitshift colorizationColor to get the RGBA values out.

Dai
  • 141,631
  • 28
  • 261
  • 374