Exemplo n.º 1
0
        /// <summary>
        /// Returns a GDI+ copy of the icon from the
        /// ImageList at the specified index.
        /// </summary>
        /// <param name="index">
        /// Index of the image.
        /// </param>
        /// <param name="small">
        /// True to get a small size Icon or false otherwise.
        /// </param>
        /// <returns>
        /// The specified Icon if successful or null otherwise.
        /// </returns>
        public Icon GetIcon(int index, bool small)
        {
            IntPtr iconPtr;

            if (small)
            {
                iconPtr = ShellAPI.ImageList_GetIcon(smallImageListHandle, index, ShellAPI.ILD.NORMAL);
            }
            else
            {
                iconPtr = ShellAPI.ImageList_GetIcon(largeImageListHandle, index, ShellAPI.ILD.NORMAL);
            }

            if (iconPtr != IntPtr.Zero)
            {
                Icon icon = Icon.FromHandle(iconPtr);
                Icon res  = (Icon)icon.Clone();
                ShellAPI.DestroyIcon(iconPtr);
                return(res);
            }
            else
            {
                return(null);
            }
        }