skyzaDev skyzaDev - 3 months ago 42
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:
http://img818.imageshack.us/img818/6337/8j1l.png

Thanks

Answer

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;
    pPropGrid->GetWindowRect(&rect);
    ScreenToClient(&rect);
    dc.Rectangle(&rect);
    dc.SelectObject(BluePen);

    CDialogEx::OnPaint();

It draws a custom border around the control.