How do I get the header height of a Listview

前端 未结 5 860
太阳男子
太阳男子 2020-12-31 09:58

Can somebody tell me how to get the header height of a ListView.

5条回答
  •  星月不相逢
    2020-12-31 10:08

    Here's how to get the listview header height using Win32 Interop calls.

    [Serializable, StructLayout(LayoutKind.Sequential)]
    public struct RECT 
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }
    
    const long LVM_FIRST = 0x1000;
    const long LVM_GETHEADER = (LVM_FIRST + 31);
    
    [DllImport("user32.dll", EntryPoint="SendMessage")]
    private static extern IntPtr SendMessage(IntPtr hwnd, long wMsg, long wParam, long lParam);
    
    [DllImport("user32.dll")]
    private static extern bool GetWindowRect(HandleRef hwnd, out RECT lpRect);
    
    RECT rc = new RECT();
    IntPtr hwnd = SendMessage(ListView1.Handle, LVM_GETHEADER, 0, 0);
    if (hwnd != null) 
    {
        if (GetWindowRect(new HandleRef(null, hwnd), out rc)) 
        {
            int headerHeight = rc.Bottom - rc.Top;
        }
    }
    

提交回复
热议问题