0

How can I change color of a property(single property among all other properties) in CMFCPropertyGridCtrl?

Suman Reddy
  • 91
  • 1
  • 13

2 Answers2

3

You need to derive a class from the CMFCPropertyGridCtrol class, and override the CMFCPropertyGridCtrl::OnDrawProperty method. This allows you to change the device context to your liking prior to calling the default implementation:

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 );
    }
};
IInspectable
  • 46,945
  • 8
  • 85
  • 181
0

CMFCPropertyGridCtrl.SetCustomColors(...) will do it.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 03 '23 at 09:16