如何设置 CMFCPropertyListCtrl 的列宽?
我向 CMFCPropertyGridCtrl
类型的对象添加属性,如下所示:
myPropertyListCtrl.AddProperty(
new CMFCPropertyGridProperty(
_T("Name"),
foo.GetName())
);
结果是只有第二列可见,但应包含“Name”的第一列不可见。
- 我找到了
CMFCPropertyGridCtrl::GetPropertyColumnWidth()
但似乎没有相应的Set...
方法... - 我查看了
NewControls
示例,其中列大小调整似乎是全自动的。但是,我找不到与我的代码相关的差异。
我缺少什么?
I'm adding properties to an object of type CMFCPropertyGridCtrl
like this:
myPropertyListCtrl.AddProperty(
new CMFCPropertyGridProperty(
_T("Name"),
foo.GetName())
);
The result is that only the second column is visible but not the first that should contain "Name".
- I found
CMFCPropertyGridCtrl::GetPropertyColumnWidth()
but there appears to be no correspondingSet...
method... - I looked at the
NewControls
sample, in which the column sizing appears to be fully automatic. However, I couldn't find the relevant difference to my code.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
m_nLeftColumnWidth
负责保存“Name”列的宽度,是CMFCPropertyGridCtrl
类的protected
成员。创建您自己的类,该类派生自CMFCPropertyGridCtrl
,您将能够操作m_nLeftColumnWidth
。m_nLeftColumnWidth
responsible for holding the "Name" column's width is aprotected
member of theCMFCPropertyGridCtrl
class. Create your own class, that derives fromCMFCPropertyGridCtrl
and you will be able to manipulatem_nLeftColumnWidth
.请注意,m_nLeftColumnWidth 在 CMFCPropertyGridCtrl 的构造函数中最初设置为 0。它被设置的其他几个地方之一是在 OnSize() 方法中(参考 AfxPropertyGridCtrl.cpp,VS2010 中的第 2783 行),它被设置为网格宽度的一半。这可能并不理想,也不是通过重写类来显式设置它所描述的自定义值,但可能已经足够好了。
如果是这样,那么它只是触发 CMFCPropertyGridCtrl::OnSize() 受保护方法。当在可调整大小的窗口(例如 CDockablePane)中使用时,将自动调用 OnSize()。但在 CDialog 中,需要显式触发,例如发送 WM_SIZE 消息:
Note that m_nLeftColumnWidth is initially set to 0 in CMFCPropertyGridCtrl's ctor. One of the few other places that it is set, is in the OnSize() method (ref. AfxPropertyGridCtrl.cpp, line 2783 in VS2010), where it is set to half the width of the grid. This may not be ideal, nor the customized value described by overriding the class to explicitly set it, but may be good enough.
If so, then it is merely to trigger having the CMFCPropertyGridCtrl::OnSize() protected method. When used in a resizable window such as a CDockablePane, OnSize() will be called automatically. But in a CDialog, it needs to be trigger explicitly such as to send a WM_SIZE message:
“设置”不存在的原因是因为它留给了标题控件。下面是通过MFC处理与发布窗口消息的方法:
The reason the "set" isn't there is because it's left to the header control. The below is the method of handling through MFC versus posting window messages: