2011-12-24 113 views
0

我正在使用圖像列表在列表視圖中顯示圖像。到目前爲止,我能夠顯示圖像列表中的所有圖像,但每個圖像之間的間距非常大。所以我用了Send Message method這引起了另一個問題。現在,當我單擊或移動鼠標(啓用熱追蹤)時,圖像變得不可見。我怎麼解決這個問題 ?如何調整列表視圖中圖像間的間距

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 

鼠標移動之前:

enter image description here

移動鼠標後:

enter image description here

我也有這個大左旁雖然列表視圖頁邊距設置爲所有= 3

第一列圖像未被顯示!

enter image description here

+0

'LVM_SETICONSPACING'僅適用於與 「圖標」 視圖樣式列表視圖。那是你正在使用的? – 2011-12-24 14:26:42

+0

@CodyGray我正在使用Listview.View = LargeIcon – 2011-12-24 14:30:26

回答

0

在你的X和Y參數,你必須包括寬度和圖標的高度。

MSDN(http://msdn.microsoft.com/en-us/library/windows/desktop/bb761176(v=vs.85).aspx):

值lParam的是相對於一個圖標 位圖的左上角。因此,要設置不重疊的圖標之間的間距,lParam值必須包含圖標的大小,再加上圖標之間所需的空白區域的數量 。不包括圖標寬度的值將導致重疊。

而且你需要反轉:

x * 65536 + y -> x + y * 65536 

y是HIWORD,x是LOWORD

相關問題