/// <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="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> /// <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> public void DrawImage( IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags, int cx, int cy, System.Drawing.Color foreColor, ImageListDrawStateConstants stateFlags, System.Drawing.Color saturateColorOrAlpha, System.Drawing.Color glowOrShadowColor) { IMAGELISTDRAWPARAMS pimldp = new IMAGELISTDRAWPARAMS(); pimldp.HdcDst = hdc; pimldp.Size = Marshal.SizeOf(pimldp.GetType()); pimldp.Index = index; pimldp.X = x; pimldp.Y = y; pimldp.CX = cx; pimldp.CY = cy; pimldp.ForegroundRgb = Color.FromArgb(0, foreColor.R, foreColor.G, foreColor.B).ToArgb(); pimldp.Style = (int)flags; pimldp.State = (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.Effect = glowOrShadowColor.ToArgb(); if (this.imageList == null) { pimldp.Himl = this.himl; int ret = ImageList_DrawIndirect(ref pimldp); } else { this.imageList.Draw(ref pimldp); } }
/// <summary> /// Draws an image to the specified context. /// </summary> /// <param name="hdc"></param> /// <param name="index"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="flags"></param> static void DrawImage(IImageList iImageList, IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags) { 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); }
/// <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); } }
//static int CLR_NONE = (int)0xffffffff; //static int CLR_INVALID = CLR_NONE; //static int CLR_DEFAULT = (int)0xff000000; private Bitmap getBitmap(int index, ImageListDrawItemConstants flags) { Size bitmapSize = GetImageListIconSize(); Bitmap bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height); using (Graphics g = Graphics.FromImage(bitmap)) { try { g.FillRectangle(Brushes.White, new Rectangle(0, 0, bitmapSize.Width, bitmapSize.Height)); IntPtr hdc = g.GetHdc(); IMAGELISTDRAWPARAMS pimldp = new IMAGELISTDRAWPARAMS(); pimldp.hdcDst = hdc; pimldp.cbSize = Marshal.SizeOf(pimldp.GetType()); pimldp.i = index; pimldp.x = 0; pimldp.y = 0; pimldp.cx = bitmapSize.Width; pimldp.cy = bitmapSize.Height; //pimldp.rgbBk = Color.Silver.ToArgb(); //pimldp.rgbFg = Color.Silver.ToArgb(); //pimldp.crEffect = Color.White.ToArgb(); //pimldp.Frame = 255; //pimldp.fState = 0x00000008; //pimldp.dwRop = (int)(dwRop.BLACKNESS); pimldp.fStyle = (int)flags; if (_iImageList == null || Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA) { int ret = ImageList_DrawIndirect(ref pimldp); } else { _iImageList.Draw(ref pimldp); } } finally { g.ReleaseHdc(); } } bitmap.MakeTransparent(); return(bitmap); }
/// <summary> /// Draws an image using the specified flags and state on XP systems. /// </summary> /// <param name="il">The image list from which an item will be drawn</param> /// <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="stateFlags">State flags</param> public static bool DrawImage(ImageList il, IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags, int cx, int cy, ImageListDrawStateConstants stateFlags) { 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 = CLR_DEFAULT; pimldp.fStyle = (uint)flags; pimldp.fState = (uint)stateFlags; pimldp.himl = il.Handle; return(ImageList_DrawIndirect(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) { 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); } }
/// <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 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.Size = Marshal.SizeOf(pimldp.GetType()); pimldp.Index = index; pimldp.X = x; pimldp.Y = y; pimldp.CX = cx; pimldp.CY = cy; pimldp.Style = (int)flags; if (this.imageList == null) { pimldp.Himl = this.himl; int ret = ImageList_DrawIndirect(ref pimldp); } else { this.imageList.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, System.Drawing.Color foreColor, ImageListDrawStateConstants stateFlags, System.Drawing.Color saturateColorOrAlpha, System.Drawing.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 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 /// </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); } }
/// <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 (this.imageList == null) { int ret = ImageList_Draw( this.himl, index, hdc, x, y, (int)flags); } else { IMAGELISTDRAWPARAMS pimldp = new IMAGELISTDRAWPARAMS(); pimldp.HdcDst = hdc; pimldp.Size = Marshal.SizeOf(pimldp.GetType()); pimldp.Index = index; pimldp.X = x; pimldp.Y = y; pimldp.ForegroundRgb = -1; pimldp.Style = (int)flags; this.imageList.Draw(ref pimldp); } }
/// <summary> /// Draws an image using the specified flags and state on XP systems. /// </summary> /// <param name="il">The image list from which an item will be drawn</param> /// <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="stateFlags">State flags</param> public static bool DrawImage(ImageList il, IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags, int cx, int cy, ImageListDrawStateConstants stateFlags) { 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 = CLR_DEFAULT; pimldp.fStyle = (uint) flags; pimldp.fState = (uint) stateFlags; pimldp.himl = il.Handle; return ImageList_DrawIndirect(ref pimldp); }