/// <summary> /// Associates a SysImageList with a TreeView control /// </summary> /// <param name="treeView">TreeView control to associated ImageList with</param> /// <param name="sysImageList">System Image List to associate</param> /// <param name="forStateImages">Whether to add ImageList as StateImageList</param> public static void SetTreeViewImageList( TreeView treeView, SystemImageList sysImageList, bool forStateImages ) { IntPtr wParam = (IntPtr)API.TVSIL_NORMAL; if (forStateImages) { wParam = (IntPtr)API.TVSIL_STATE; } API.SendMessage( treeView.Handle, API.TVM_SETIMAGELIST, wParam, sysImageList.Handle); }
public static int GetIconIndex(string Extension) { const int FILE_ATTRIBUTE_NORMAL = 0x80; SystemImageList.SHGetFileInfoConstants dwFlags = SystemImageList.SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES | SystemImageList.SHGetFileInfoConstants.SHGFI_SYSICONINDEX | SystemImageList.SHGetFileInfoConstants.SHGFI_SMALLICON; SystemImageList.SHFILEINFO shfi = new SystemImageList.SHFILEINFO(); uint shfiSize = (uint)Marshal.SizeOf(shfi.GetType()); SystemImageList.SHGetFileInfo( Extension, FILE_ATTRIBUTE_NORMAL, ref shfi, shfiSize, (uint)dwFlags); return(shfi.iIcon); }
/// <summary> /// Associates a SysImageList with a ListView control /// </summary> /// <param name="listView">ListView control to associate ImageList with</param> /// <param name="sysImageList">System Image List to associate</param> /// <param name="forStateImages">Whether to add ImageList as StateImageList</param> public static void SetListViewImageList( ListView listView, SystemImageList sysImageList, bool forStateImages ) { IntPtr wParam = (IntPtr)API.LVSIL_NORMAL; if (sysImageList.ImageListSize == SystemImageListSize.SmallIcons) { wParam = (IntPtr)API.LVSIL_SMALL; } if (forStateImages) { wParam = (IntPtr)API.LVSIL_STATE; } API.SendMessage( listView.Handle, API.LVM_SETIMAGELIST, wParam, sysImageList.Handle); }