【发布时间】:2017-08-25 09:17:00
【问题描述】:
我在查看:列表模式中有一个ListView。
我的问题是间距。我只有图像,我想要一个水平滚动。
问题是这样的:
图像之间的巨大差距。当我使用 View: LargeIcons 或 Tile 模式时,也存在差距,但是,这已使用 LVM_SETICONSPACING 解决。但是 tile/largeicons 是垂直滚动的,这是我不想要的。
所以我可以做两件事,但不知道如何实现。 1.弄清楚如何在列表模式下固定间距。 2. 使 LargeIcons/Tile 模式水平滚动。
我将附上一些处理列表视图的代码:
这是适用于平铺/大图标的图标间距:
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=False)>
Private Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Param) As Int32
End Function
<StructLayout(LayoutKind.Explicit)>
Private Structure Param
<FieldOffset(0)> Public LoWord As Int16
<FieldOffset(2)> Public HiWord As Int16
End Structure
Private Const LVM_FIRST As Integer = &H1000
Private Const LVM_SETICONSPACING As Integer = LVM_FIRST + 53
Public Sub SetListviewIconSpacing(lv As ListView, ByVal x As Int16, ByVal y As Int16)
' The LOWORD specifies the distance, in pixels, to set between icons on the x-axis.
' The HIWORD specifies the distance, in pixels, to set between icons on the y-axis.
Dim lparam As Param = New Param With {.LoWord = x, .HiWord = y}
SendMessage(lv.Handle, LVM_SETICONSPACING, 0, lparam)
lv.Refresh()
End Sub
这是使用图像列表添加图像的一般编码:
Dim img As Image
Dim imgList As ImageList = New ImageList()
Dim listItem As ListViewItem
'''SetListviewIconSpacing(lstViewAH, 101, 103)
imgList.ColorDepth = ColorDepth.Depth16Bit
imgList.ImageSize = New Size(92, 92)
lstViewAH.StateImageList = imgList
lstViewAH.LargeImageList = imgList
lstViewAH.SmallImageList = imgList
For i As Integer = 0 To arrX.Count - 1
img = Image.FromFile(CharactersFolder & "000" & arrX(i).ToString() & ".jpg")
imgList.Images.Add("itemImageKey" & i, img)
listItem = New ListViewItem("", "itemImageKey" & i)
listItem.UseItemStyleForSubItems = False
listItem.Tag = arrX(i)
lstViewAH.Items.Add(listItem)
Next
有什么想法吗?
【问题讨论】:
-
PictureBoxes 在FlowLayoutPanel中有什么问题? -
哦,我没听说过。使用 FlowLayoutPanel 并添加控件实际上效果非常好。记忆力似乎并没有更糟,但也许我错了,因为图像太小了。
-
你可以为自己的问题写一个答案并接受它:)
-
实际上一直在搞砸它,但现在我正在进行动态测试,它显然慢了很多。问题似乎不在于加载图像,而是与将所有新控件(图片框)添加到流程中有关。我尝试暂停/恢复布局和 AddRange,而不是一次添加每个,但由于我有大量图像,这需要相当多的时间。有什么建议吗?
-
显然只在调试模式下发生,没关系。
标签: .net vb.net listview imagelist