Click here to Skip to main content
13,091,363 members (55,160 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 2 Mar 2010

Windows Ribbon for WinForms, Part 9 – Changing Ribbon Colors

, 10 Mar 2010
Rate this:
Please Sign up or sign in to vote.
In this article, I'll present how to change the ribbon colors.

This series of CodeProject articles is based on a series of posts I've first published on my blog.

Introduction to the Feature

The feature I want to talk about today is how to change the ribbon general colors. Note that you can't change the colors of a specific ribbon item, only the entire ribbon.

There are 3 colors we can change:

  • Background Color
  • Highlight Color
  • Text Color

Here is an example of a colored ribbon:


How To Do It?

I've added a new method to the RibbonLib.Ribbon class in my Windows Ribbon for WinForms library.
Following is an example of how to use it:

private void Form1_Load(object sender, EventArgs e)
    // init ribbon framework

    // set ribbon colors
    _ribbon.SetColors(Color.Wheat, Color.IndianRed, Color.BlueViolet);

Behind the Scenes

What the SetColors method actually does is:

  • Get IPropertyStore interface from the IUIFramework (which represents the ribbon framework)
  • Create 3 PropVariant variables that will hold the 3 colors we want to set
  • Convert the colors: RGB –> HSL –> HSB –> uint, see next section
  • Set the relevant properties with the converted colors values
public void SetColors(Color background, Color highlight, Color text)
    if (_framework == null)
    IPropertyStore propertyStore = (IPropertyStore)_framework;
    PropVariant backgroundColorProp = new PropVariant();
    PropVariant highlightColorProp = new PropVariant();
    PropVariant textColorProp = new PropVariant();

    uint backgroundColor = ColorHelper.HSB2uint(
    uint highlightColor = ColorHelper.HSB2uint(
    uint textColor = ColorHelper.HSB2uint(
    propertyStore.SetValue(ref RibbonProperties.UI_PKEY_GlobalBackgroundColor, 
                           ref backgroundColorProp);
    propertyStore.SetValue(ref RibbonProperties.UI_PKEY_GlobalHighlightColor, 
                           ref highlightColorProp);
    propertyStore.SetValue(ref RibbonProperties.UI_PKEY_GlobalTextColor, 
                           ref textColorProp);

Color Format

I didn't dive into the colors format world, so I'll just give a quick reference.

RGB is the well known color format that we, developers, like and understand.

RGB can be converted to HSL. This should be a common transformation or as Microsoft wrote here, “easily accomplished with most photo editing software”. In this page, Microsoft also gives the formulas for converting HSL to HSB.

Here, you can find C# code for transforming RGB to HSL and vice versa.

Finally HSB is converted to uint by just OR-ing the values, much like RGB to uint conversion.
I've encapsulated all these details in a helper class named RibbonLib.ColorHelper.

A new sample, named 07-RibbonColor, summarizes the details of this post. Find it on the project site.

That’s it for now,
Arik Poznanski.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Arik Poznanski
Software Developer (Senior) Verint
Israel Israel
Arik Poznanski is a senior software developer at Verint. He completed two B.Sc. degrees in Mathematics & Computer Science, summa cum laude, from the Technion in Israel.

Arik has extensive knowledge and experience in many Microsoft technologies, including .NET with C#, WPF, Silverlight, WinForms, Interop, COM/ATL programming, C++ Win32 programming and reverse engineering (assembly, IL).

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170813.1 | Last Updated 10 Mar 2010
Article Copyright 2010 by Arik Poznanski
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid