CListCtrl 中的垂直滚动条

发布于 2024-08-13 09:46:09 字数 173 浏览 10 评论 0原文

我在图标视图中使用 CListCtrl,但它水平滚动:

1 3 5 7 -->
2 4 6 8 -->

我宁愿它水平滚动:

1 2
3 4
5 6
| |
V V

有办法做到这一点吗?

I'm using a CListCtrl in Icon view, but it scrolls horizontally:

1 3 5 7 -->
2 4 6 8 -->

I'd rather it scroll horizontally:

1 2
3 4
5 6
| |
V V

Is there a way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

嘿咻 2024-08-20 09:46:09

将设计器中的对齐方式从左更改为上。

Change the Alignment style in designer from Left to Top.

挽手叙旧 2024-08-20 09:46:09

我似乎已经通过使用“报告”视图解决了该问题。通过 VS 设计器,这意味着将“视图”样式更改为报告,从而使控件在 .RC 文件中具有 LVS_REPORT 属性。请注意,这相当于在代码中调用 CListCtrl::SetView(LV_VIEW_DETAILS)。但这还不够。如果您还没有一个列,则还需要通过几行代码创建一个列:

m_lstScenarios.InsertColumn(0, L"NO HEADER");
m_lstScenarios.SetColumnWidth(k_nListColScenario, LVSCW_AUTOSIZE);

如果您不需要列标题,请通过“无列标题”样式在设计器中设置 LVS_NOCOLUMNHEADER 。

I seem to have resolved the issue by using a 'Report' view. Through the VS Designer this means changing the 'View' style to Report, resulting the control given the LVS_REPORT attribute in the .RC file. Note that this is equivalent to calling CListCtrl::SetView(LV_VIEW_DETAILS) in code. This isn't sufficient however. It is also necessary to create a column if you don't already have one with a couple lines of code:

m_lstScenarios.InsertColumn(0, L"NO HEADER");
m_lstScenarios.SetColumnWidth(k_nListColScenario, LVSCW_AUTOSIZE);

If you don't want the column header, set the LVS_NOCOLUMNHEADER in the Designer through the 'No Column Header' style.

思念满溢 2024-08-20 09:46:09

在 Visual Studio 对话框编辑器上,确保您有“列表控件”,而不是“列表框”。

在 Visual Studio 对话框编辑器的属性列表中,将“无列标题”设置为“真”,将“查看”设置为“报告”。 (将“Alignment”设置为 Left 在报表模式下没有任何效果。)

OnInitDialog() 中,执行以下操作(在调用超类的 OnInitDialog() 后):

  CListCtrl* plistError = (CListCtrl*) GetDlgItem( IDC_ERROR );
  plistError->InsertColumn( 0, "" );
  plistError->SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER );

事实上,这似乎给出了创建控件的初始宽度的最大自动大小。字符串在该点显示为截断并带有省略号。扩大窗口并没有帮助。

要纠正此问题,请向您的 CDialog 子类添加一个方法 OnSize(),该方法再次提醒列表它更宽。 (这里假设加宽窗口可以让 CListCtrl 显示更多文本。如果您有其他方法,例如按钮,请尝试此 SetColumnWidth() 调用,其中然后,

 WinProgress::OnSize() {
    CListCtrl* plist = (CListCtrl*) GetDlgItem( IDC_ERROR );
    plist->SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER );

您可以使用以下代码将新行添加到列表底部:

  CListCtrl* plist = (CListCtrl*) GetDlgItem( IDC_ERROR );
  int iCount = plist->GetItemCount();

  plist->InsertItem( iCount, "Next Item" );

对于列表来说太宽的项目将首先显示省略号。当您稍微调整窗口大小时,列表项会变宽到完整大小,并在必要时出现水平滚动条。就外观和感觉而言,它并不完全是 10/10,但即使是经验丰富的 GUI 程序员也可能不会注意到。

On the Visual Studio dialog editor, make sure you have a "List Control," not a "List Box."

On the Visual Studio dialog editor's property list, set "No Column Header" to True and "View" to Report. (Setting "Alignment" to Left has no effect in Report mode.)

In OnInitDialog(), do the following (after calling your superclass's OnInitDialog()):

  CListCtrl* plistError = (CListCtrl*) GetDlgItem( IDC_ERROR );
  plistError->InsertColumn( 0, "" );
  plistError->SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER );

In fact, that seems to give a maximum autosize of the initial width the control is created with. Strings are displayed truncated with an ellipsis at that point. Widening the window does not help.

To correct that, add a method OnSize() to your CDialog subclass that again reminds the list that it's wider. (This assumes that widening the window is what would let the CListCtrl display more text. If you have some other means, such as a button, try this SetColumnWidth() call where you're doing that.)

 WinProgress::OnSize() {
    CListCtrl* plist = (CListCtrl*) GetDlgItem( IDC_ERROR );
    plist->SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER );

You may then add new rows to the bottom of the list with code such as:

  CListCtrl* plist = (CListCtrl*) GetDlgItem( IDC_ERROR );
  int iCount = plist->GetItemCount();

  plist->InsertItem( iCount, "Next Item" );

Items too wide for the list will show ellipses at first. When you resize the window however slightly, then the list items wide to full size and a horizontal scrollbar appears if necessary. It's not quite 10/10 as far as look and feel are concerned but even experienced GUI programmers probably won't notice.

栀子花开つ 2024-08-20 09:46:09

在列表控件中,要在单列中显示带图像的内容,并带有垂直滚动条。添加以下代码,
在 PreCreateWindow 函数中,添加以下行
cs.style |= (LVS_REPORT|LVS_NOCOLUMNHEADER);
并在 OnIntialUpdate 函数中添加以下行,
fileList.InsertColumn(0," ",LVCFMT_LEFT|LVCFMT_IMAGE,120,-1);
ShowScrollBar(SB_VERT,1);
之后,无论您想在列表中的何处插入数据,都可以,但要注意设置 imagelist,然后使用 insertitem 插入数据,例如:
fileList,insertitem(0,"印度",1);
其中 1->是图像在图像列表中的索引。

In list control,to display content with image in single column with vertical scrollbar .add following code,
In PreCreateWindow function,add following line
cs.style |= (LVS_REPORT|LVS_NOCOLUMNHEADER);
and in OnIntialUpdate function add following line,
fileList.InsertColumn(0," ",LVCFMT_LEFT|LVCFMT_IMAGE,120,-1);
ShowScrollBar(SB_VERT,1);
after this,whereever you want to insert data in list you can but take care that you set imagelist and then insert data using insertitem eg:
fileList,insertitem(0,"India",1);
where 1-> is index of image in imagelist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文