LISTVIEW往HEADER里加图片的东东

  // Declare this structure first
 [System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
  struct HDITEM
 {
      public uint mask;
      public int cxy;
      public IntPtr pszText;    // !!!!!! If anybody should know how i can pass a string here instead of an IntPtr (which is a hack), please let me know!!!!!!!
      public IntPtr hbm;
     public int cchTextMax;
     public int fmt;
     public IntPtr lParam;
     public int iImage;
     public int iOrder;
     public uint type;
     public IntPtr pvFilter;
 }

 // Put this declaration in your class
 [DllImport("USER32.DLL", EntryPoint= "SendMessage";)]
 public static extern IntPtr SendMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam);

 // Make a SetHeaderImageList function
 private void SetHeaderImageList(ListView lv, ImageList il)
 {
     // Get the header ctrl
     int LVM_GETHEADER = 0x1000 + 31;
     IntPtr hwndHeader = SendMessage(lv.Handle, LVM_GETHEADER, new IntPtr(0), new IntPtr(0));
     // Set the imagelist of the header ctrl
     int HDM_SETIMAGELIST = 0x1200 + 8;
     SendMessage(hwndHeader, HDM_SETIMAGELIST, new IntPtr(0), il.Handle);
 }

 // Make a SetHeaderImage function
 unsafe private void SetHeaderImage(ColumnHeader ch, int imageIndex)
 {
     // Get the header ctrl
     int LVM_GETHEADER = 0x1000 + 31;
     IntPtr hwndHeader = SendMessage(ch.ListView.Handle, LVM_GETHEADER, new IntPtr(0), new IntPtr(0));
     // Put the image in the header
     uint HDI_IMAGE = 0x0020;
     uint HDI_FORMAT = 0x0004;
     int HDF_LEFT = 0;
     int HDF_STRING = 0x4000;
     int HDF_IMAGE = 0x0800;
     int HDM_SETITEM = 0x1200 + 4;
     HDITEM hdItem = new HDITEM();
     hdItem.mask = HDI_IMAGE | HDI_FORMAT;
     hdItem.fmt = HDF_LEFT | HDF_STRING | HDF_IMAGE;
     hdItem.iImage = imageIndex;
     SendMessage(hwndHeader, HDM_SETITEM, new IntPtr(0), new IntPtr(&hdItem));
 }


 Now use these functions to set the imagelist, and then to set the image (set
 the imagelist only once)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值