Partager via


CMFCColorButton Class

The CMFCColorButton and CMFCColorBar Class classes are used together to implement a color picker control.

class CMFCColorButton : public CMFCButton

Members

Public Constructors

Name

Description

CMFCColorButton::CMFCColorButton

Constructs a new CMFCColorButton object.

Public Methods

Name

Description

CMFCColorButton::EnableAutomaticButton

Enables and disables an "automatic" button that is positioned above the regular color buttons. (The standard system automatic button is labeled Automatic.)

CMFCColorButton::EnableOtherButton

Enables and disables an "other" button that is positioned below the regular color buttons. (The standard system "other" button is labeled More Colors….)

CMFCColorButton::GetAutomaticColor

Retrieves the current automatic color.

CMFCColorButton::GetColor

Retrieves a button's color.

CMFCColorButton::SetColor

Sets a button's color.

CMFCColorButton::SetColorName

Sets a color name.

CMFCColorButton::SetColumnsNumber

Sets the number of columns on the color picker dialog box.

CMFCColorButton::SetDocumentColors

Specifies a list of document-specific colors that are displayed on the color picker dialog box.

CMFCColorButton::SetPalette

Specifies a palette of standard display colors.

CMFCColorButton::SizeToContent

Changes the size of the button control, depending on its text and image size.

Protected Methods

Name

Description

CMFCColorButton::IsDrawXPTheme

Indicates whether the current color button is displayed in the visual style of Windows XP.

CMFCColorButton::OnDraw

Called by the framework to display an image of the button.

CMFCColorButton::OnDrawBorder

Called by the framework to display the button's border.

CMFCColorButton::OnDrawFocusRect

Called by the framework to display a focus rectangle when the button has a focus.

CMFCColorButton::OnShowColorPopup

Called by the framework when the color picker dialog box is about to be displayed.

CMFCColorButton::RebuildPalette

Initializes the m_pPalette protected data member to the specified palette or the default system palette.

CMFCColorButton::UpdateColor

Called by the framework when the user selects a color from the palette of the color picker dialog box.

Data Members

Name

Description

m_bAltColorDlg

A Boolean. If TRUE, the framework displays the CMFCColorDialog color dialog box when the other button is clicked, or if FALSE, the system color dialog box. The default value is TRUE. For more information, see CMFCColorButton::EnableOtherButton.

m_bAutoSetFocus

A Boolean. If TRUE, the framework sets the focus on the color menu when the menu is displayed, or if FALSE, does not change the focus. The default value is TRUE.

CMFCColorButton::m_bEnabledInCustomizeMode

Indicates whether customization mode is enabled for the color button.

m_Color

A COLORREF value. Contains the currently selected color.

m_ColorAutomatic

A COLORREF value. Contains the currently selected default color.

m_Colors

A CArray of COLORREF values. Contains the currently available colors.

m_lstDocColors

A CList of COLORREF values. Contains the current document colors.

m_nColumns

An integer. Contains the number of columns to display in the grid of colors in a color selection menu.

m_pPalette

A pointer to a CPalette. Contains the colors that are available in the current color selection menu.

m_pPopup

A pointer to a CMFCColorPopupMenu Class object. The color selection menu that is displayed when you click the color button.

m_strAutoColorText

A string. The label of the "automatic" button in a color selection menu.

m_strDocColorsText

A string. The label of the button in a color selection menu that displays the document colors.

m_strOtherText

A string. The label of the "other" button in a color selection menu.

Remarks

By default, the CMFCColorButton class behaves as a push button that opens a color picker dialog box. The color picker dialog box contains an array of small color buttons and an "other" button that displays a custom color picker. (The standard system "other" button is labeled More Colors….) When a user selects a new color, the CMFCColorButton object reflects the change and displays the selected color.

Create a color button control either directly in your code, or by using the ClassWizard tool and a dialog box template. If you create a color button control directly, add a CMFCColorButton variable to your application, and then call the constructor and Create methods of the CMFCColorButton object. If you use the ClassWizard, add a CButton variable to your application, and then change the type of the variable from CButton to CMFCColorButton.

The color picker dialog box (CMFCColorBar Class) is displayed by the CMFCColorButton::OnShowColorPopup method when the framework calls the OnLButtonDown event handler. The CMFCColorButton::OnShowColorPopup method can be overridden to support custom color selection.

The CMFCColorButton object notifies its parent that a color is changing by sending it a WM_COMMAND | BN_CLICKED notification. The parent uses the CMFCColorButton::GetColor method to retrieve the current color.

Example

The following example demonstrates how to configure a color button by using various methods in the CMFCColorButton class. The methods set the color of the color button and its number of columns, and enable the automatic and the other buttons. This example is part of the Status Bar Demo sample.

   CMFCColorButton m_wndTextColor;


...


    m_wndTextColor.EnableAutomaticButton (_T("Default"), afxGlobalData.clrBtnText);
    m_wndTextColor.EnableOtherButton (_T("Other..."));
    m_wndTextColor.SetColor ((COLORREF)-1);
    m_wndTextColor.SetColorName((COLORREF)-1, "Default Color");
    m_wndTextColor.SetColumnsNumber(3);

Requirements

Header: afxcolorbutton.h

See Also

Reference

Hierarchy Chart

CMFCButton Class

CMFCColorBar Class

CMFCColorButton::OnShowColorPopup

COLORREF

CPalette Class

CArray Class

CList Class

CString

Other Resources

MFC Classes