我正在使用图像列表在列表视图中显示图像。到目前为止,我能够显示图像列表中的所有图像,但每个图像之间的间距非常大。所以我使用了Send Message 方法,这引起了另一个问题。现在,当我单击或将鼠标移到(启用热跟踪)任何图像时,图像变得不可见。我怎么解决这个问题 ?
Imports System.Runtime.InteropServices
Public Class Form1
<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 Int32) As Int32
End Function
Const LVM_FIRST As Integer = &H1000
Const LVM_SETICONSPACING As Integer = LVM_FIRST + 53
Public Sub SetSpacing(ByVal x As Int16, ByVal y As Int16)
SendMessage(Me.ListView1.Handle, LVM_SETICONSPACING, 0, x * 65536 + y)
Me.ListView1.Refresh()
End Sub
Private Sub Display()
For i As Integer = 0 To ImageList1.Images.Count - 1
Dim item As New ListViewItem()
item.ImageIndex = i
Me.ListView1.Items.Add(item)
Next
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Display()
SetSpacing(200, 16)
End Sub
End Class
鼠标移动之前:
鼠标移动后:
我也有这么大的左边距,虽然 listview 边距设置为 All = 3
图片的第一列没有显示!!!