예제 #1
0
        /// <summary>
        /// Retrieves a thumbnail for the specified file.
        /// </summary>
        /// <param name="fileInfo">File to retrieve the thumbnail for.</param>
        /// <returns>Image thumbnail.</returns>
        public static Image Thumbnail(this FileInfo fileInfo)
        {
            try
            {
                ShellThumbnail thumb = new ShellThumbnail();

                return(thumb.GetThumbnail(fileInfo.FullName));
            }
            catch (Exception)
            {
                // create a dummy file to extract the icon from
                string tempPath = string.Format("{0}{1}{2}", Path.GetTempPath(), StringUtilities.GetRandomString(10), fileInfo.Extension);

                File.Create(tempPath);

                SysImageList list = new SysImageList(SysImageListSize.extraLargeIcons);

                Bitmap bitmap = list.Icon(list.IconIndex(tempPath)).ToBitmap();

                File.Delete(tempPath);

                Bitmap copy = bitmap.Copy();

                return(copy);
            }
        }
예제 #2
0
        /// <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, SysImageList sysImageList, bool forStateImages)
        {
            IntPtr param = (IntPtr)TVSILNORMAL;

            if (forStateImages)
            {
                param = (IntPtr)TVSILSTATE;
            }

            SendMessage(treeView.Handle, TVMSETIMAGELIST, param, sysImageList.Handle);
        }
예제 #3
0
        /// <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, SysImageList sysImageList, bool forStateImages)
        {
            IntPtr param = (IntPtr)LVSILNORMAL;

            if (sysImageList.ImageListSize == SysImageListSize.smallIcons)
            {
                param = (IntPtr)LVSILSMALL;
            }

            if (forStateImages)
            {
                param = (IntPtr)LVSILSTATE;
            }

            SendMessage(listView.Handle, LVMSETIMAGELIST, param, sysImageList.Handle);
        }