简体   繁体   English

MFC PropertyGrid 控件在visual studio 的对话框编辑器中是如何工作的?

[英]How does the MFC PropertyGrid control work in the dialog editor in visual studio?

In the visual studio dialog editor i can add a MFC Property Grid control to the dailog.在 Visual Studio 对话框编辑器中,我可以将 MFC 属性网格控件添加到 dailog。 How can i customize its content, and set options like allowing the user to edit the contents of it when the program using it is running, or how i can change the contents of it using c++?我如何自定义它的内容,并设置选项,例如允许用户在使用它的程序运行时编辑它的内容,或者我如何使用 C++ 更改它的内容? When i add something like a button or and edit control it displays on the dailog box when the program is running, while when i add a MFC Property Grid the dailog isnt even being displayed.当我添加按钮或编辑控件之类的东西时,它会在程序运行时显示在 dailog 框中,而当我添加 MFC 属性网格时,dailog 甚至没有显示。 在此处输入图片说明

Here is a picture of the visual studio dialog editor and a MFC property control grid in the middle of the dailog with contents i dont know how to change.这是一个 Visual Studio 对话框编辑器的图片和一个位于 dailog 中间的 MFC 属性控件网格,其中包含我不知道如何更改的内容。

Simple tutorial of CMFCPropertyGridCtrl: CMFCPropertyGridCtrl 简单教程:

1.Create a dialog-based MFC project, drag a CMFCPropertyGridCtrl into it, and adjust the size. 1.创建一个基于对话框的MFC项目,拖一个CMFCPropertyGridCtrl进去,调整大小。 Then change the ID for the control to IDC_MFCPROPERTYGRID_TEST, and use Add Varible to add a variable m_propertyGrid to the control.然后将控件的 ID 更改为 IDC_MFCPROPERTYGRID_TEST,并使用 Add Varible 向控件添加变量 m_propertyGrid。 Change the setting of Notify to True .将 Notify 的设置更改为True 在此处输入图片说明

Description Rows Count refers to the number of rows in the description section below. Description Rows Count refers下面描述部分中的行数。

Enable Description Area indicates whether to enable the following description function. Enable Description Area指示是否启用以下描述功能。

Enable Header indicates whether to start the header. Enable Header表示是否启动头部。

Mark Modified Properties indicates whether to highlight the changes. Mark Modified Properties指示是否突出显示更改。

2.Set interface Add the following code in OnInitDialog() 2.设置接口在OnInitDialog()添加如下代码

HDITEM item; 
item.cxy=120; 
item.mask=HDI_WIDTH; 
m_propertyGrid.GetHeaderCtrl().SetItem(0, new HDITEM(item)); 
  1. Add content添加内容

Add the following code in OnInitDialog()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);

The three parameters passed in when calling the constructor are item name , default options and description text .调用构造函数时传入的三个参数是item namedefault optionsdescription text

Also, you could add drop-down menu:此外,您可以添加下拉菜单:

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);

In addition, there are three similar projects:此外,还有三个类似的项目:

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);

Finally, This is the final program running interface:最后,这是最终的程序运行界面: 在此处输入图片说明

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

相关问题 如何在可视对话框编辑器中将MFC控件连接到自定义控件 - How to connect an MFC control to a custom control in the visual dialog editor MFC Propertygrid控件未绘制边框? - MFC Propertygrid control not drawing a border? 调试 MFC header 代码不适用于 Visual Studio 2019 - Debugging into MFC header code does not work with Visual Studio 2019 带有选项卡控件的基于 MFC 对话框的应用程序 - Visual Studio 错误/限制使推荐路径不可能? - MFC dialog-based app with tab control - Visual Studio bugs/restrictions make recommended path impossible? MFC对话框控件的“接受文件”选项如何工作? - How does the “Accept Files” option for MFC dialog controls work? MFC 中的自定义 slider 控件(视觉工作室) - Custom slider control in MFC (visual studio) 如何在MFC中访问主对话框的元素? 在视觉编辑器VS 2012中创建了Element - How to get access to main dialog's element in MFC? Element was created in visual editor VS 2012 Tab控件中的嵌入式对话框无法在第二个对话框MFC中使用 - Embedded dialog in Tab Control cannot work in second dialog, MFC 如何正确添加MFC链接控制到Dialog? - How to properly add MFC Link Control to Dialog? 如何在MFC对话框中替换/更新ActiveX控件 - How to replace/update an ActiveX control in a MFC dialog
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM