Skip to content

DropDownColorPicker

harborsiem edited this page Apr 29, 2024 · 4 revisions

DropDownColorPicker

Windows Ribbon for WinForms library now supports DropDownColorPicker control. The result of this post is a yet another sample, “11-DropDownColorPicker”, found on the project site.

ColorPicker1

DropDownColorPicker Control The drop-down color picker looks like this:

ColorPicker2

DropDownColorPicker Properties (with internal details) Following is the list of properties which are unique for DropDownColorPicker control. The rest of the properties have been reviewed in previous posts.

  • Color – The selected color. Property Identifier: UI_PKEY_Color

  • ColorType – The type of selected color. Can be: NoColor, Automatic or RGB (meaning specific color). Property Identifier: UI_PKEY_ColorType

  • AutomaticColorLabel – Defines the label for the “Automatic” color button. Property Identifier: UI_PKEY_AutomaticColorLabel

  • MoreColorsLabel – Defines the label for the “More colors…” button. Property Identifier: UI_PKEY_MoreColorsLabel

  • NoColorLabel – Defines the label for the “No color” button. Property Identifier: UI_PKEY_NoColorLabel

  • RecentColorsCategoryLabel – Defines the label for the “Recent colors” category. Property Identifier: UI_PKEY_RecentColorsCategoryLabel

  • StandardColorsCategoryLabel – Defines the label for the “Standard colors” category. Property Identifier: UI_PKEY_StandardColorsCategoryLabel

  • ThemeColorsCategoryLabel – Defines the label for the “Theme colors” category. Property Identifier: UI_PKEY_ThemeColorsCategoryLabel

!Note:
The different labels in the drop down color picker allows you to localize the control.

For more details on DropDownColorPicker control, check out Drop-Down Color Picker on MSDN.

Using DropDownColorPicker – Ribbon Markup

Commands and Views sections:

<?xml version='1.0' encoding='utf-8'?>
<Application xmlns='http://schemas.microsoft.com/windows/2009/Ribbon'>
  <Application.Commands>
    <Command Name="cmdDropDownColorPickerThemeColors"
             Id="1002"
             LabelTitle="Theme Colors">
      <Command.LargeImages>
        <Image>Res/Colors32.bmp</Image>
      </Command.LargeImages>
    </Command>
  </Application.Commands>
  <Application.Views>
    <Ribbon>
      <Ribbon.Tabs>
        <Tab>
          <Group>
            <DropDownColorPicker CommandName="cmdDropDownColorPickerThemeColors"
                                 ColorTemplate="ThemeColors"/>
          </Group>
        </Tab>
      </Ribbon.Tabs>
    </Ribbon>
  </Application.Views>
</Application>

Using DropDownColorPicker – Code Behind

Initializing:

private Ribbon _ribbon;
private RibbonDropDownColorPicker _themeColors;
public Form1()
{
    InitializeComponent();
    _ribbon = new Ribbon();
    _themeColors = new RibbonDropDownColorPicker(_ribbon, (uint)RibbonMarkupCommands.cmdDropDownColorPickerThemeColors);
}
private void Form1_Load(object sender, EventArgs e)
{
    InitDropDownColorPickers();
}
private void InitDropDownColorPickers()
{
    // common properties
    _themeColors.Label = "Theme Colors";
    _themeColors.ExecuteEvent += new EventHandler<ExecuteEventArgs>(_themeColors_ExecuteEvent);
    // set labels
    _themeColors.AutomaticColorLabel = "My Automatic";
    _themeColors.MoreColorsLabel = "My More Colors";
    _themeColors.NoColorLabel = "My No Color";
    _themeColors.RecentColorsCategoryLabel = "My Recent Colors";
    _themeColors.StandardColorsCategoryLabel = "My Standard Colors";
    _themeColors.ThemeColorsCategoryLabel = "My Theme Colors";
    // set colors
    _themeColors.ThemeColorsTooltips = new string[] { "yellow", "green", "red", "blue" };
    _themeColors.ThemeColors = new Color[] { Color.Yellow, Color.Green, Color.Red, Color.Blue };
}

Respond to selected color event:

void _themeColors_ExecuteEvent(object sender, ExecuteEventArgs e)
{
    ColorPickerEventArgs args = ColorPickerEventArgs.Create(sender, e);
    ...
    MessageBox.Show("Selected color is " + _themeColors.Color.ToString());
}

Older code:

void _themeColors_ExecuteEvent(object sender, ExecuteEventArgs e)
{
    MessageBox.Show("Selected color is " + _themeColors.Color.ToString());
}

Table of contents

Clone this wiki locally