C# 更改 ListView 项目/行的高度 [英] C# Change ListView Item's/Row's height

查看:45
本文介绍了C# 更改 ListView 项目/行的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在列表视图中更改项目/行的高度.

I want to change the Item's/Row's height in listview.

我搜索了每一个地方,我发现为了改变高度,我需要使用 LBS_OWNERDRAWFIXEDMeasureItem 或类似的东西.

I searched every where and I figured that in order to change the height I need to use LBS_OWNERDRAWFIXED or MeasureItem or something like that.

问题是我不知道该做什么以及如何使用它..
有人可以帮我吗?

The problem is that I dont know exactly what to do and how to use it..
Can anyone help me with it?


我不能使用 ImageList hack,因为我使用的是真正的 SmallImageList 并且我需要与 ImageList 图像大小不同的行高.


I cant use the ImageList hack because I am using the SmallImageList for real and I need different line height from the ImageList images size.

谢谢!

推荐答案

它可以使用 SmallImageList 技巧来完成——你只需要小心.ObjectListView -- 一个围绕标准 .NET ListView 的开源包装器 -- 使用了这个技巧成功实现 RowHeight 属性.

It can be done using the SmallImageList trick -- you just have to be careful. ObjectListView -- an open source wrapper around a standard .NET ListView -- uses that trick to successfully implement a RowHeight property.

如果您想要每行 32 像素,请分配一个 16x32(宽 x 高)的 ImageList,然后将您的每张图像放置在 32 像素高度的垂直中间.

If you want 32 pixels for each row, allocate an ImageList that is 16x32 (width x height), and then position each of your images in the vertical middle of the 32-pixel height.

此屏幕截图显示了 32 像素的行以及由于额外空间而可能出现的自动换行:

This screen shot shows 32-pixel rows and the word wrapping that is possible because of the extra space:

ObjectListView 为您完成所有这些工作.事实上,如果你想用 ListView 做任何事情,你应该认真考虑使用 ObjectListView 代替.它使许多困难的事情(例如按列类型排序、自定义工具提示)变得微不足道,并使一些不可能的事情(例如覆盖、虚拟列表上的组)成为可能.

ObjectListView does all this work for you. In fact, if you are trying to do anything with a ListView, you should seriously looked at using an ObjectListView instead. It makes many difficult things (e.g. sorting by column type, custom tooltips) trivial, and several impossible things (e.g. overlays, groups on virtual lists) possible.

这篇关于C# 更改 ListView 项目/行的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆