private static extern int ImageList_DrawIndirect( ref IMAGELISTDRAWPARAMS pimldp);
/// <summary> /// Draws an image using the specified flags and specifies /// the size to clip to (or to stretch to if ILD_SCALE /// is provided). /// </summary> /// <param name="hdc">Device context to draw to</param> /// <param name="index">Index of image to draw</param> /// <param name="x">X Position to draw at</param> /// <param name="y">Y Position to draw at</param> /// <param name="flags">Drawing flags</param> /// <param name="cx">Width to draw</param> /// <param name="cy">Height to draw</param> public void DrawImage( IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags, int cx, int cy ) { IMAGELISTDRAWPARAMS pimldp = new IMAGELISTDRAWPARAMS(); pimldp.hdcDst = hdc; pimldp.cbSize = Marshal.SizeOf(pimldp.GetType()); pimldp.i = index; pimldp.x = x; pimldp.y = y; pimldp.cx = cx; pimldp.cy = cy; pimldp.fStyle = (int)flags; if (_iImageList == null) { pimldp.himl = _hIml; int ret = ImageList_DrawIndirect(ref pimldp); } else { _iImageList.Draw(ref pimldp); } }
/// <summary> /// Draws an image using the specified flags and state on XP systems. /// </summary> /// <param name="hdc">Device context to draw to</param> /// <param name="index">Index of image to draw</param> /// <param name="x">X Position to draw at</param> /// <param name="y">Y Position to draw at</param> /// <param name="flags">Drawing flags</param> /// <param name="cx">Width to draw</param> /// <param name="cy">Height to draw</param> /// <param name="foreColor">Fore colour to blend with when using the /// ILD_SELECTED or ILD_BLEND25 flags</param> /// <param name="stateFlags">State flags</param> /// <param name="glowOrShadowColor">If stateFlags include ILS_GLOW, then /// the colour to use for the glow effect. Otherwise if stateFlags includes /// ILS_SHADOW, then the colour to use for the shadow.</param> /// <param name="saturateColorOrAlpha">If stateFlags includes ILS_ALPHA, /// then the alpha component is applied to the icon. Otherwise if /// ILS_SATURATE is included, then the (R,G,B) components are used /// to saturate the image.</param> public void DrawImage( IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags, int cx, int cy, Color foreColor, ImageListDrawStateConstants stateFlags, Color saturateColorOrAlpha, Color glowOrShadowColor ) { IMAGELISTDRAWPARAMS pimldp = new IMAGELISTDRAWPARAMS(); pimldp.hdcDst = hdc; pimldp.cbSize = Marshal.SizeOf(pimldp.GetType()); pimldp.i = index; pimldp.x = x; pimldp.y = y; pimldp.cx = cx; pimldp.cy = cy; pimldp.rgbFg = Color.FromArgb(0, foreColor.R, foreColor.G, foreColor.B).ToArgb(); Console.WriteLine("{0}", pimldp.rgbFg); pimldp.fStyle = (int)flags; pimldp.fState = (int)stateFlags; if ((stateFlags & ImageListDrawStateConstants.ILS_ALPHA) == ImageListDrawStateConstants.ILS_ALPHA) { // Set the alpha: pimldp.Frame = (int)saturateColorOrAlpha.A; } else if ((stateFlags & ImageListDrawStateConstants.ILS_SATURATE) == ImageListDrawStateConstants.ILS_SATURATE) { // discard alpha channel: saturateColorOrAlpha = Color.FromArgb(0, saturateColorOrAlpha.R, saturateColorOrAlpha.G, saturateColorOrAlpha.B); // set the saturate color pimldp.Frame = saturateColorOrAlpha.ToArgb(); } glowOrShadowColor = Color.FromArgb(0, glowOrShadowColor.R, glowOrShadowColor.G, glowOrShadowColor.B); pimldp.crEffect = glowOrShadowColor.ToArgb(); if (_iImageList == null) { pimldp.himl = _hIml; int ret = ImageList_DrawIndirect(ref pimldp); } else { _iImageList.Draw(ref pimldp); } }
/// <summary> /// Draws an image using the specified flags /// </summary> /// <param name="hdc">Device context to draw to</param> /// <param name="index">Index of image to draw</param> /// <param name="x">X Position to draw at</param> /// <param name="y">Y Position to draw at</param> /// <param name="flags">Drawing flags</param> public void DrawImage( IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags ) { if (_iImageList == null) { int ret = ImageList_Draw( _hIml, index, hdc, x, y, (int)flags); } else { IMAGELISTDRAWPARAMS pimldp = new IMAGELISTDRAWPARAMS(); pimldp.hdcDst = hdc; pimldp.cbSize = Marshal.SizeOf(pimldp.GetType()); pimldp.i = index; pimldp.x = x; pimldp.y = y; pimldp.rgbFg = -1; pimldp.fStyle = (int)flags; _iImageList.Draw(ref pimldp); } }