如何设置 CMFCPropertyListCtrl 的列宽?

发布于 2024-09-14 06:29:15 字数 447 浏览 3 评论 0原文

我向 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 corresponding Set... 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乙白 2024-09-21 06:29:15

m_nLeftColumnWidth 负责保存“Name”列的宽度,是 CMFCPropertyGridCtrl 类的 protected 成员。创建您自己的类,该类派生自 CMFCPropertyGridCtrl,您将能够操作 m_nLeftColumnWidth

m_nLeftColumnWidth responsible for holding the "Name" column's width is a protected member of the CMFCPropertyGridCtrl class. Create your own class, that derives from CMFCPropertyGridCtrl and you will be able to manipulate m_nLeftColumnWidth.

離殇 2024-09-21 06:29:15

请注意,m_nLeftColumnWidth 在 CMFCPropertyGridCtrl 的构造函数中最初设置为 0。它被设置的其他几个地方之一是在 OnSize() 方法中(参考 AfxPropertyGridCtrl.cpp,VS2010 中的第 2783 行),它被设置为网格宽度的一半。这可能并不理想,也不是通过重写类来显式设置它所描述的自定义值,但可能已经足够好了。

如果是这样,那么它只是触发 CMFCPropertyGridCtrl::OnSize() 受保护方法。当在可调整大小的窗口(例如 CDockablePane)中使用时,将自动调用 OnSize()。但在 CDialog 中,需要显式触发,例如发送 WM_SIZE 消息:

CRect rect;
myPropGrid.GetWindowRect(&rect);
myPropGrid.PostMessage(WM_SIZE, 0, MAKELONG(rect.Width(),rect.Height()));

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:

CRect rect;
myPropGrid.GetWindowRect(&rect);
myPropGrid.PostMessage(WM_SIZE, 0, MAKELONG(rect.Width(),rect.Height()));
甩你一脸翔 2024-09-21 06:29:15

“设置”不存在的原因是因为它留给了标题控件。下面是通过MFC处理与发布窗口消息的方法:

HDITEM hdItem;
hdItem.mask = HDI_WIDTH; // indicating cxy is width
hdItem.cxy = 300; // whatever you want the property name column width to be
PropListCtrl.GetHeaderCtrl().SetItem(0, &hdItem);

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:

HDITEM hdItem;
hdItem.mask = HDI_WIDTH; // indicating cxy is width
hdItem.cxy = 300; // whatever you want the property name column width to be
PropListCtrl.GetHeaderCtrl().SetItem(0, &hdItem);
清旖 2024-09-21 06:29:15
class CServerPropertyGridCtrl : public CMFCPropertyGridCtrl
{
public:
    void SetLeftColumnWidth(int cx)
    {
        m_nLeftColumnWidth = cx;
        AdjustLayout();
    }
};
class CServerPropertyGridCtrl : public CMFCPropertyGridCtrl
{
public:
    void SetLeftColumnWidth(int cx)
    {
        m_nLeftColumnWidth = cx;
        AdjustLayout();
    }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文