如何在 CMFCPropertyGridCtrl 中更改 属性 的颜色

How to change the color of a property in CMFCPropertyGridCtrl

如何更改 CMFCPropertyGridCtrl 中 属性(所有其他属性中的单个 属性)的颜色?

您需要从 CMFCPropertyGridCtrol class, and override the CMFCPropertyGridCtrl::OnDrawProperty 方法派生一个 class。这允许您在调用默认实现之前根据自己的喜好更改设备上下文:

class CMFCMyPropertyGridCtrl : public CMFCPropertyGridCtrl {

public:
    virtual int OnDrawProperty( CDC * pDC, CMFCPropertyGridProperty* pProp ) const {
        // Implement check to see, if this is the property we are looking for
        // If it is, set an appropriate text color
        pDC->SetTextColor( RGB( 0xff, 0x0, 0xff ) );

        // Call the default implementation to perform rendering
        return CMFCPropertyGridCtrl::OnDrawProperty( pDC, pProp );
    }
};