简体   繁体   English

MFC Propertygrid控件未绘制边框?

[英]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). 我已经在窗体上创建了CMFCPropertyGridCtrl,但是,在Visual Studio的“属性”窗口中将该控件的“边框”选项设置为“真”时,它没有任何效果,并且属性网格看起来始终像下面的屏幕截图所示(没有在控件周围绘制边框)。

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 无边界控件: 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: 在对话框的重写的OnPaint方法中,添加以下代码:

    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. Visaul Studio包含以下错误:资源编辑器不会在对话框资源中的控件说明中添加边框样式。 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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