ListView 的 View 設定為 LargeIcon 時,ICON 之間內定的距離是沒辦法透過設定來縮小的.
找了一陣子才發現,可以透過這個 Function 來修改內定的距離.
using System.Runtime.InteropServices;
/// <summary>
/// 控制ListView項之間的距離
/// </summary>
/// <param name="Handle"></param>
/// <param name="wMsg"></param>
/// <param name="wParam">水平間距</param>
/// <param name="lParam">垂直間距</param>
/// <returns></returns>
[DllImport("User32.dll")]
private static extern int SendMessage(int Handle, int wMsg, int wParam, int lParam);
const int LVM_FIRST = 0x1000;
const int LVM_SETICONSPACING = LVM_FIRST + 53;
public static void SetListViewSpacing(ListView lst, int x, int y)
{
SendMessage(lst.Handle.ToInt32(), LVM_SETICONSPACING, 0, x * 65536 + y);
}
全站熱搜