Dela via


CMFCRibbonColorButton Class

The CMFCRibbonColorButton class implements a color button that you can add to a ribbon bar. The ribbon color button displays a drop-down menu that contains one or more color palettes.

class CMFCRibbonColorButton : public CMFCRibbonGallery

Members

Public Constructors

Name

Description

CMFCRibbonColorButton::CMFCRibbonColorButton

Constructs and initializes a CMFCRibbonColorButton object.

Public Methods

Name

Description

CMFCRibbonColorButton::AddColorsGroup

Adds a group of colors to the regular color area.

CMFCRibbonColorButton::EnableAutomaticButton

Specifies whether the Automatic button is enabled.

CMFCRibbonColorButton::EnableOtherButton

Enables the Other button.

CMFCRibbonColorButton::GetAutomaticColor

Retrieves the current automatic (default) color.

CMFCRibbonColorButton::GetColor

Returns the currently selected color.

CMFCRibbonColorButton::GetColorBoxSize

Returns the size of the color elements that appear on the color bar.

CMFCRibbonColorButton::GetColumns

Retrieves the number of color items per row that are shown in the regular color area.

CMFCRibbonColorButton::GetHighlightedColor

Returns the color of the currently selected element on the popup color palette.

CMFCRibbonColorButton::RemoveAllColorGroups

Removes all color groups from the regular color area.

CMFCRibbonColorButton::SetColor

Selects a color from the regular color area.

CMFCRibbonColorButton::SetColorBoxSize

Sets the size of all the color elements that appear on the color bar.

CMFCRibbonColorButton::SetColorName

Sets a new name for a specified color.

CMFCRibbonColorButton::SetColumns

Sets the number of color items per row that are shown in the regular color area.

CMFCRibbonColorButton::SetDocumentColors

Specifies a list of RGB values to display in the document color area.

CMFCRibbonColorButton::SetPalette

Sets the list of selectable colors that are visible in the regular color area.

CMFCRibbonColorButton::UpdateColor

Used internally.

Remarks

The ribbon color button displays a color bar when a user presses it. By default, this color bar contains a color selection palette called the regular color area. Optionally, the color bar can display an Automatic button, which allows the user to select a default color, and an Other button, which displays a popup color palette that contains additional colors.

Example

The following example demonstrates how to use various methods in the CMFCRibbonColorButton class. The example shows how to construct a CMFCRibbonColorButton object, set the large image, enable the Automatic button, enable the Other button, set the number of columns, set the size of all the color elements that appear on the color bar, add a group of colors to the regular color area, and specify a list of RGB values to display in the document color area. This code snippet is part of the DrawClient Sample: MFC Ribbon-Based OLE Object Drawing Application.

// Create the "Paper Color" button
    CMFCRibbonColorButton* pBtnPaperColor = new CMFCRibbonColorButton(ID_VIEW_PAPERCOLOR, _T("Paper Color\ng"), TRUE, 13, 1);
    pBtnPaperColor->SetAlwaysLargeImage();
    pBtnPaperColor->EnableAutomaticButton(_T("&Automatic"), RGB(255, 255, 255));
    pBtnPaperColor->EnableOtherButton(_T("&More Colors..."), _T("More Colors"));
    pBtnPaperColor->SetColumns(10);
    pBtnPaperColor->SetColorBoxSize(CSize(17, 17));
    // CList<COLORREF,COLORREF> m_lstMainColors
    pBtnPaperColor->AddColorsGroup(_T("Theme Colors"), m_lstMainColors, TRUE);
    // CList<COLORREF,COLORREF> m_lstAdditionalColors
    pBtnPaperColor->AddColorsGroup(_T(""), m_lstAdditionalColors, FALSE);
    // CList<COLORREF,COLORREF> m_lstStandardColors
    pBtnPaperColor->AddColorsGroup(_T("Standard Colors"), m_lstStandardColors, TRUE);
    CList<COLORREF,COLORREF> lstColors;
    lstColors.AddTail(RGB(255,0,0));
    lstColors.AddTail(RGB(0,255,0));
    lstColors.AddTail(RGB(0,0,255));
    pBtnPaperColor->SetDocumentColors( _T("Document Colors"), lstColors );

Inheritance Hierarchy

CObject

   CMFCRibbonBaseElement

      CMFCRibbonButton

         CMFCRibbonGallery

            CMFCRibbonColorButton

Requirements

Header: afxribboncolorbutton.h

See Also

Concepts

MFC Hierarchy Chart

Reference

CMFCRibbonGallery Class

Other Resources

Classes (MFC Feature Pack)