我有一个视图中的ListView
:列表模式。
我的问题是每隔一步。我只是有图像,我想要一个水平滚动。
问题是:
图像之间有很大的差距。当Iw使用View: LargeIcons或Tile模式时,也存在空白,但是,这是使用LVM_SETICONSPACING解决的。然而,瓷砖/大图标是垂直滚动,这是我不想。
所以有两件事我可以做,但不知道如何实现。1.找出如何在列表模式下确定间距。2.使大型图标/瓷砖模式水平滚动。
我将附加一些处理列表视图的代码:
下面是用于平铺/大图标的图标间距:
<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
有什么想法吗?
发布于 2017-08-25 21:04:49
使用FlowLayoutPanel的简单方法是:
FlowLayoutPanel1.SuspendLayout()
FlowLayoutPanel1.AutoScroll = False
For i As Integer = 0 To arrX.Count - 1
Dim newImage As New DoubleBufferImage
newImage.Load(CharactersFolder & "000" & arrX(i).ToString() & ".jpg")
newImage.Tag = arrX(i).ToString()
newImage.Width = 96
newImage.Height = 96
FlowLayoutPanel1.Controls.Add(newImage)
Next
FlowLayoutPanel1.AutoScroll = True
FlowLayoutPanel1.ResumeLayout()
您也可以使用AddRange加载图像,但我假设持有数组的内存要重一些。速度相当快,所以没问题。我禁用了AutoScroll,因为autoscroll需要时间重新计算并在之后启用它。好像工作得很好,像我想的那样有水平滚动条。
注意:在调试模式下添加大量控件是缓慢的。在VS之外的非调试/释放模式EXE中,情况并非如此。
https://stackoverflow.com/questions/45878186
复制相似问题