Setting the BackColor to match the Office 2007 color scheme

Daniel Molina, a developer on my team, shared this code which is useful if you want to detect the Office color scheme (e.g. black, silver, blue) and try to match the backcolor of your ActionsPane or other UI you show to match that color.

A couple of caveats:

– The user might change the color scheme while running the Office application and there is no event that is available to tell you this.  So the user would have to restart the Office application to see the new theme color reflected in your custom UI.

-This code is hard coded to Office 2007, and there are no guarantees that it would work in the next version of Office (and it won’t work with Office 2003 since there isn’t this notion of color schemes).

        public static void GetBackColor(out byte r, out byte g, out byte b)
const string OfficeCommonKey =
const string OfficeThemeValueName = “Theme”;
const int ThemeBlue = 1;
const int ThemeSilver = 2;
const int ThemeBlack = 3;

using (RegistryKey key = Registry.CurrentUser.
OpenSubKey(OfficeCommonKey, false))
int theme = (int)key.GetValue(OfficeThemeValueName);

switch (theme)
case ThemeBlue:
r = 227;
g = 239;
b = 255;

case ThemeSilver:
case ThemeBlack:
r = 240;
g = 241;
b = 242;

var color = System.Windows.SystemColors.ControlColor;
r = color.R;
g = color.G;
b = color.B;

Skip to main content