skyzaDev skyzaDev - 1 year ago 99
C++ Question

MFC Propertygrid control not drawing a border?

I have created a CMFCPropertyGridCtrl on my form, however when setting the "Border" option to "True" in visual studio's Properties window for that control, it has no effects and the property grid always looks like it does in the below screenshot (with no border drawn around the control).

I also tried to enable the border from within my code but with no luck.

What are my options? Is this some kind of bug? I was thinking perhaps manually drawing a rectangle around the control to simulate a border as a last resort.

The border-less control:


Answer Source

So I found a solution myself

In the overridden OnPaint method of your dialog box add the following code:

    CMFCPropertyGridCtrl* pPropGrid = (CMFCPropertyGridCtrl*) GetDlgItem(IDC_PROPSYSCHECK); 
    CPaintDC dc(this);
    CPen BluePen(PS_SOLID, 1, RGB(137, 140, 149));
    CPen *OldPen = dc.SelectObject(&BluePen);
    CRect rect;


It draws a custom border around the control.