public static extern IntPtr ImageList_GetIcon(IntPtr himl, int i, IMAGELISTDRAWFLAGS flags);
/// <summary> /// Draws the image indicated by the given index on the specified <see cref="Graphics"/> at the specified location. /// </summary> /// <param name="imageList">The image list.</param> /// <param name="g">The <see cref="Graphics"/> to draw on.</param> /// <param name="bounds">The bounds in which to draw the image. Set width and height to 0 to draw image at full size.</param> /// <param name="index">The index of the image in the ImageList to draw.</param> /// <param name="bgColor">The background color of the image. This parameter can be a <see cref="Color"/> value or <see cref="ImageListDrawColor.None"/> /// so the image is drawn transparently or <see cref="ImageListDrawColor.Default"/> so the image is drawn using the background color of the image list.</param> /// <param name="fgColor">The foreground color of the image. This parameter can be a <see cref="Color"/> value or <see cref="ImageListDrawColor.None"/> /// so the image is blended with the color of the destination device context or <see cref="ImageListDrawColor.Default"/> so the image is drawn using the system highlight color as the foreground color.</param> /// <param name="style">The drawing style.</param> /// <param name="overlayImageIndex">Optional index of an overlay image.</param> /// <exception cref="System.ComponentModel.Win32Exception">Unable to draw the image with defined parameters.</exception> public static void Draw(this ImageList imageList, Graphics g, Rectangle bounds, int index, ImageListDrawColor bgColor, ImageListDrawColor fgColor, IMAGELISTDRAWFLAGS style = IMAGELISTDRAWFLAGS.ILD_NORMAL, int overlayImageIndex = 0) { if (index < 0 || index >= imageList.Images.Count) { throw new ArgumentOutOfRangeException(nameof(index)); } if (overlayImageIndex < 0 || overlayImageIndex > imageList.GetOverlayCount()) { throw new ArgumentOutOfRangeException(nameof(overlayImageIndex)); } using (var hg = new SafeDCHandle(g)) if (!ImageList_DrawEx(new HandleRef(imageList, imageList.Handle), index, hg, bounds.X, bounds.Y, bounds.Width, bounds.Height, bgColor, fgColor, style | (IMAGELISTDRAWFLAGS)(overlayImageIndex << 8))) { throw new Win32Exception(); } }
public static extern bool ImageList_DrawEx(HandleRef himl, int i, SafeDCHandle hdcDst, int x, int y, int dx, int dy, uint rgbBk, uint rgbFg, IMAGELISTDRAWFLAGS fStyle);
/// <summary>Draws the image indicated by the given index on the specified <see cref="Graphics"/> at the specified location.</summary> /// <param name="imageList">The image list.</param> /// <param name="g">The <see cref="Graphics"/> to draw on.</param> /// <param name="bounds">The bounds in which to draw the image. Set width and height to 0 to draw image at full size.</param> /// <param name="index">The index of the image in the ImageList to draw.</param> /// <param name="bgColor"> /// The background color of the image. This parameter can be a <see cref="Color"/> value or <see cref="COLORREF.None"/> so the image is drawn /// transparently or <see cref="COLORREF.Default"/> so the image is drawn using the background color of the image list. /// </param> /// <param name="fgColor"> /// The foreground color of the image. This parameter can be a <see cref="Color"/> value or <see cref="COLORREF.None"/> so the image is blended /// with the color of the destination device context or <see cref="COLORREF.Default"/> so the image is drawn using the system highlight color /// as the foreground color. /// </param> /// <param name="style">The drawing style.</param> /// <param name="overlayImageIndex">Optional index of an overlay image.</param> /// <exception cref="System.ComponentModel.Win32Exception">Unable to draw the image with defined parameters.</exception> public static void Draw(this ImageList imageList, Graphics g, Rectangle bounds, int index, COLORREF bgColor, COLORREF fgColor, IMAGELISTDRAWFLAGS style = IMAGELISTDRAWFLAGS.ILD_NORMAL, int overlayImageIndex = 0) { if (index < 0 || index >= imageList.Images.Count) { throw new ArgumentOutOfRangeException(nameof(index)); } if (overlayImageIndex < 0 || overlayImageIndex > imageList.GetOverlayCount()) { throw new ArgumentOutOfRangeException(nameof(overlayImageIndex)); } using (var hg = new SafeHDC(g)) { var p = new IMAGELISTDRAWPARAMS(hg, bounds, index, bgColor, style | (IMAGELISTDRAWFLAGS)INDEXTOOVERLAYMASK(overlayImageIndex)) { rgbFg = fgColor }; imageList.GetIImageList().Draw(p); } }