![](/img/trans.png)
[英]How to connect an MFC control to a custom control in the visual dialog editor
[英]How does the MFC PropertyGrid control work in the dialog editor in visual studio?
CMFCPropertyGridCtrl 简单教程:
1.创建一个基于对话框的MFC项目,拖一个CMFCPropertyGridCtrl进去,调整大小。 然后将控件的 ID 更改为 IDC_MFCPROPERTYGRID_TEST,并使用 Add Varible 向控件添加变量 m_propertyGrid。 将 Notify 的设置更改为True
。
Description Rows Count refers
下面描述部分中的行数。
Enable Description Area
指示是否启用以下描述功能。
Enable Header
表示是否启动头部。
Mark Modified Properties
指示是否突出显示更改。
2.设置接口在OnInitDialog()
添加如下代码
HDITEM item;
item.cxy=120;
item.mask=HDI_WIDTH;
m_propertyGrid.GetHeaderCtrl().SetItem(0, new HDITEM(item));
在OnInitDialog()
添加以下代码
CMFCPropertyGridProperty* pProp2 = new CMFCPropertyGridProperty(
_T("choose"),
_T("select"),
_T(""));
pProp2->AddOption(_T("1"));
pProp2->AddOption(_T("2"));
pProp2->AddOption(_T("3"));
pProp2->AllowEdit(FALSE); //Editing of options is not allowed
m_propertyGrid.AddProperty(pProp2);
调用构造函数时传入的三个参数是item name
、 default options
和description text
。
此外,您可以添加下拉菜单:
CMFCPropertyGridProperty* pProp2 = new CMFCPropertyGridProperty(
_T("choose"),
_T("select"),
_T(""));
pProp2->AddOption(_T("1"));
pProp2->AddOption(_T("2"));
pProp2->AddOption(_T("3"));
pProp2->AllowEdit(FALSE); //Editing of options is not allowed
m_propertyGrid.AddProperty(pProp2);
此外,还有三个类似的项目:
CMFCPropertyGridColorProperty * pProp3 = new CMFCPropertyGridColorProperty(
_T("colour"), RGB(0, 111, 200));
m_propertyGrid.AddProperty(pProp3);
CMFCPropertyGridFileProperty * pProp4 = new CMFCPropertyGridFileProperty(
_T("open file"), TRUE, _T("D:\\test.txt"));
m_propertyGrid.AddProperty(pProp4);
LOGFONT font = { NULL };
CMFCPropertyGridFontProperty * pProp5 = new CMFCPropertyGridFontProperty(
_T("select font"), font);
m_propertyGrid.AddProperty(pProp5);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.