CListCtrl 中的垂直滚动条
我在图标视图中使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将设计器中的对齐方式从左更改为上。
Change the Alignment style in designer from Left to Top.
我似乎已经通过使用“报告”视图解决了该问题。通过 VS 设计器,这意味着将“视图”样式更改为报告,从而使控件在 .RC 文件中具有 LVS_REPORT 属性。请注意,这相当于在代码中调用
CListCtrl::SetView(LV_VIEW_DETAILS)
。但这还不够。如果您还没有一个列,则还需要通过几行代码创建一个列:如果您不需要列标题,请通过“无列标题”样式在设计器中设置 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:If you don't want the column header, set the LVS_NOCOLUMNHEADER in the Designer through the 'No Column Header' style.
在 Visual Studio 对话框编辑器上,确保您有“列表控件”,而不是“列表框”。
在 Visual Studio 对话框编辑器的属性列表中,将“无列标题”设置为“真”,将“查看”设置为“报告”。 (将“Alignment”设置为 Left 在报表模式下没有任何效果。)
在
OnInitDialog()
中,执行以下操作(在调用超类的OnInitDialog()
后):事实上,这似乎给出了创建控件的初始宽度的最大自动大小。字符串在该点显示为截断并带有省略号。扩大窗口并没有帮助。
要纠正此问题,请向您的
CDialog
子类添加一个方法OnSize()
,该方法再次提醒列表它更宽。 (这里假设加宽窗口可以让CListCtrl
显示更多文本。如果您有其他方法,例如按钮,请尝试此SetColumnWidth()
调用,其中然后,您可以使用以下代码将新行添加到列表底部:
对于列表来说太宽的项目将首先显示省略号。当您稍微调整窗口大小时,列表项会变宽到完整大小,并在必要时出现水平滚动条。就外观和感觉而言,它并不完全是 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'sOnInitDialog()
):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 yourCDialog
subclass that again reminds the list that it's wider. (This assumes that widening the window is what would let theCListCtrl
display more text. If you have some other means, such as a button, try thisSetColumnWidth()
call where you're doing that.)You may then add new rows to the bottom of the list with code such as:
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.
在列表控件中,要在单列中显示带图像的内容,并带有垂直滚动条。添加以下代码,
在 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.