我在视图:列表模式中有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
有什么想法吗?
答案 0 :(得分:2)
使用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需要时间重新计算并在之后重新启用它。似乎运作良好,并有我想要的水平滚动条。
注意:在调试模式下添加大量控件是SLOW。在VS的非调试/释放模式EXE中不是这种情况。