简体   繁体   中英

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

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.

Visaul Studio contains the bug: Resource Editor does not add border style to the control description in dialog resource. So, add this style manually and be lucky :)

BOOL CMyDlg::OnInitDialog() {
    CDialogEx::OnInitDialog();

    // add WS_BORDER style manualy...
    GetDlgItem(IDC_PROPSYSCHECK)->ModifyStyle(0, WS_BORDER);
    return TRUE;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM