Word 2003 toolbar colors

Add-in Express™ Support Service
That's what is more important than anything else

Word 2003 toolbar colors
Marek Toma

Posts: 41
Joined: 2009-01-05
We are using adxadvancedcontrol to host a UserControl in the word toolbar. We are struggling with a way to customize the background color of the UserControl.

The colors Word 2003 is using to draw toolbars are somehow derived from system colors (they do change when system colors change), but I can not find which colors are set when you right click desktop - Appearance - Advanced and set your custom colors.

Can you provide any hints how to style the UserControl to look exactly as other toolbars which natively use office colors?

EDIT: I knew about this article (http://www.add-in-express.com/creating-addins-blog/2008/03/21/custom-office-controls-colors) when I was customizing our UserControl for Office 2007 and now forgot to look at it... ProfessionalColorTable is the solution.

The question remains which colors to use from it to achieve the Office 2003 toolbar look.

I will try to post as soon as I find out but would be grateful if anyone with this knowledge posted the solution.
Posted 02 Mar, 2009 07:03:32 Top
Marek Toma

Posts: 41
Joined: 2009-01-05
OK, I found the solution:

Bitmap toolbarBackground = new Bitmap(4, 32);
using (Graphics g = Graphics.FromImage(toolbarBackground)) 
  Application.EnableVisualStyles(); //this must be called to ensure the color table returns correct values, otherwise, it would be grey all the time
  ProfessionalColorTable t = new ProfessionalColorTable();

  Color light = t.[B]ImageMarginGradientBegin[/B];
  Color dark = t.[B]ImageMarginGradientEnd[/B];

  Rectangle rect = new Rectangle(new Point(), toolbarBackground.Size);
  LinearGradientBrush b = new LinearGradientBrush(rect, light, dark, LinearGradientMode.Vertical);
  g.FillRectangle(b, rect);
//set the toolbarBackground UserControl's background and make sure it is stretched

When you handle SystemColorsChanged event in the UserControl and redraw the background, it handles any color scheme (even custom colors set by user) exactly as word does.

The Application.EnableVisualStyles is a the tricky part, otherwise, the ProfessionalColorTable is returning some default values.
Posted 02 Mar, 2009 09:47:02 Top
Sergey Grischenko

Add-in Express team

Posts: 7224
Joined: 2004-07-05
Hi Marek.

Thank you for the solution.
Posted 02 Mar, 2009 10:36:50 Top