如何调整列表视图中图像之间的间距
我正在使用图像列表在列表视图中显示图像。到目前为止,我能够显示图像列表中的所有图像,但每个图像之间的间距非常大。所以我使用了 发送消息方法< /a> 这引起了另一个问题。现在,当我单击或将鼠标移到(启用热跟踪)任何图像时,图像将变得不可见。我该如何解决这个问题?
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
鼠标移动之前:
鼠标移动之后:
尽管列表视图边距设置为 All = 3,但我的左边距也很大
图像的第一列未显示! !
I am using a image-list to show images in a list-view. So far I am able to display all the images in the image-list but spacing between each image is very big. So I used the Send Message method which gave rise to another problem. Now when I click or move my mouse over(hot tracking enabled) any image the image becomes invisible. How can I solve this problem ?
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
Before Mouse-Move:
After Mouse-Move:
Also I have this big left margin although listview margin is set to All = 3
The First column of Images is not being displayed !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 x 和 y 参数中,必须包含图标的宽度和高度。
MSDN (http://msdn .microsoft.com/en-us/library/windows/desktop/bb761176(v=vs.85).aspx):
并且您需要反转:
y 在 HIWORD 中,x 在 LOWORD 中
In your x and y arguments, you have to include the width and the height of the icons.
MSDN (http://msdn.microsoft.com/en-us/library/windows/desktop/bb761176(v=vs.85).aspx):
And you need to invert:
y is in the HIWORD, x is in the LOWORD
这是我与 LargeIcon 一起使用并起作用的东西,从这里开始:
https://qdevblog.blogspot.com/2011/11/ c-listview-item-spacing.html
然后你像这样使用它:
This is something that I used with LargeIcon and works, from here:
https://qdevblog.blogspot.com/2011/11/c-listview-item-spacing.html
Then you use it like this: