Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
 /// <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);
     }
 }
Beispiel #3
0
        /// <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);
            }
        }
Beispiel #4
0
 /// <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);
     }
 }
Beispiel #5
0
 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)
 {
     SysImageList.IMAGELISTDRAWPARAMS iMAGELISTDRAWPARAMS = default(SysImageList.IMAGELISTDRAWPARAMS);
     iMAGELISTDRAWPARAMS.hdcDst = hdc;
     iMAGELISTDRAWPARAMS.cbSize = Marshal.SizeOf(iMAGELISTDRAWPARAMS.GetType());
     iMAGELISTDRAWPARAMS.i      = index;
     iMAGELISTDRAWPARAMS.x      = x;
     iMAGELISTDRAWPARAMS.y      = y;
     iMAGELISTDRAWPARAMS.cx     = cx;
     iMAGELISTDRAWPARAMS.cy     = cy;
     iMAGELISTDRAWPARAMS.rgbFg  = Color.FromArgb(0, (int)foreColor.R, (int)foreColor.G, (int)foreColor.B).ToArgb();
     Console.WriteLine("{0}", iMAGELISTDRAWPARAMS.rgbFg);
     iMAGELISTDRAWPARAMS.fStyle = (int)flags;
     iMAGELISTDRAWPARAMS.fState = (int)stateFlags;
     if ((stateFlags & ImageListDrawStateConstants.ILS_ALPHA) == ImageListDrawStateConstants.ILS_ALPHA)
     {
         iMAGELISTDRAWPARAMS.Frame = (int)saturateColorOrAlpha.A;
     }
     else if ((stateFlags & ImageListDrawStateConstants.ILS_SATURATE) == ImageListDrawStateConstants.ILS_SATURATE)
     {
         saturateColorOrAlpha      = Color.FromArgb(0, (int)saturateColorOrAlpha.R, (int)saturateColorOrAlpha.G, (int)saturateColorOrAlpha.B);
         iMAGELISTDRAWPARAMS.Frame = saturateColorOrAlpha.ToArgb();
     }
     glowOrShadowColor            = Color.FromArgb(0, (int)glowOrShadowColor.R, (int)glowOrShadowColor.G, (int)glowOrShadowColor.B);
     iMAGELISTDRAWPARAMS.crEffect = glowOrShadowColor.ToArgb();
     if (this.iImageList == null)
     {
         iMAGELISTDRAWPARAMS.himl = this.hIml;
         int num = SysImageList.ImageList_DrawIndirect(ref iMAGELISTDRAWPARAMS);
     }
     else
     {
         this.iImageList.Draw(ref iMAGELISTDRAWPARAMS);
     }
 }
Beispiel #6
0
        /// <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
            )
        {
            var 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.IlsAlpha) ==
                ImageListDrawStateConstants.IlsAlpha)
            {
                // Set the alpha:
                pimldp.Frame = (int)saturateColorOrAlpha.A;
            }
            else if ((stateFlags & ImageListDrawStateConstants.IlsSaturate) ==
                     ImageListDrawStateConstants.IlsSaturate)
            {
                // 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;
                var ret = ImageList_DrawIndirect(ref pimldp);
            }
            else
            {
                _iImageList.Draw(ref pimldp);
            }
        }
Beispiel #7
0
        /// <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
            )
        {
            var 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;
                var ret = ImageList_DrawIndirect(ref pimldp);
            }
            else
            {
                _iImageList.Draw(ref pimldp);
            }
        }
Beispiel #8
0
 /// <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)
     {
         var ret = ImageList_Draw(
             _hIml,
             index,
             hdc,
             x,
             y,
             (int)flags);
     }
     else
     {
         var 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);
     }
 }
Beispiel #9
0
        /// <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 = 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);
            }
        }
Beispiel #10
0
        public static bool DrawImageList(Graphics g, ImageList il, int index, int x, int y, bool isSelected, bool isDisabled)
        {
            ImageListDrawItemConstants  flags = (isSelected ? ImageListDrawItemConstants.ILD_SELECTED : ImageListDrawItemConstants.ILD_NORMAL) | ImageListDrawItemConstants.ILD_TRANSPARENT;
            ImageListDrawStateConstants state = isDisabled ? ImageListDrawStateConstants.ILS_SATURATE : ImageListDrawStateConstants.ILS_NORMAL;

            try
            {
                IntPtr hdc = g.GetHdc();
                return(DrawImage(il, hdc, index, x, y, flags, 0, 0, state));
            }
            finally
            {
                g.ReleaseHdc();
            }
        }
Beispiel #11
0
        //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);
        }
Beispiel #12
0
 public void DrawImage(IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags)
 {
     if (this.iImageList == null)
     {
         int num = SysImageList.ImageList_Draw(this.hIml, index, hdc, x, y, (int)flags);
     }
     else
     {
         SysImageList.IMAGELISTDRAWPARAMS iMAGELISTDRAWPARAMS = default(SysImageList.IMAGELISTDRAWPARAMS);
         iMAGELISTDRAWPARAMS.hdcDst = hdc;
         iMAGELISTDRAWPARAMS.cbSize = Marshal.SizeOf(iMAGELISTDRAWPARAMS.GetType());
         iMAGELISTDRAWPARAMS.i      = index;
         iMAGELISTDRAWPARAMS.x      = x;
         iMAGELISTDRAWPARAMS.y      = y;
         iMAGELISTDRAWPARAMS.rgbFg  = -1;
         iMAGELISTDRAWPARAMS.fStyle = (int)flags;
         this.iImageList.Draw(ref iMAGELISTDRAWPARAMS);
     }
 }
Beispiel #13
0
        private Bitmap GetBitmap(int index, ImageListDrawItemConstants flags)
        {
            var bitmapSize = GetImageListIconSize();
            var bitmap     = new Bitmap(bitmapSize.Width, bitmapSize.Height);

            using (var g = Graphics.FromImage(bitmap))
            {
                try
                {
                    g.FillRectangle(Brushes.White, new Rectangle(0, 0, bitmapSize.Width, bitmapSize.Height));

                    var hdc = g.GetHdc();

                    var pimldp = new NativeMethods.IMAGELISTDRAWPARAMS {
                        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.fStyle = (int)flags;

                    if (_iImageList == null || Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA)
                    {
                        NativeMethods.ImageList_DrawIndirect(ref pimldp);
                    }
                    else
                    {
                        _iImageList.Draw(ref pimldp);
                    }
                }
                finally
                {
                    g.ReleaseHdc();
                }
            }

            bitmap.MakeTransparent();
            return(bitmap);
        }
Beispiel #14
0
 public void DrawImage(IntPtr hdc, int index, int x, int y, ImageListDrawItemConstants flags, int cx, int cy)
 {
     SysImageList.IMAGELISTDRAWPARAMS iMAGELISTDRAWPARAMS = default(SysImageList.IMAGELISTDRAWPARAMS);
     iMAGELISTDRAWPARAMS.hdcDst = hdc;
     iMAGELISTDRAWPARAMS.cbSize = Marshal.SizeOf(iMAGELISTDRAWPARAMS.GetType());
     iMAGELISTDRAWPARAMS.i      = index;
     iMAGELISTDRAWPARAMS.x      = x;
     iMAGELISTDRAWPARAMS.y      = y;
     iMAGELISTDRAWPARAMS.cx     = cx;
     iMAGELISTDRAWPARAMS.cy     = cy;
     iMAGELISTDRAWPARAMS.fStyle = (int)flags;
     if (this.iImageList == null)
     {
         iMAGELISTDRAWPARAMS.himl = this.hIml;
         int num = SysImageList.ImageList_DrawIndirect(ref iMAGELISTDRAWPARAMS);
     }
     else
     {
         this.iImageList.Draw(ref iMAGELISTDRAWPARAMS);
     }
 }
Beispiel #15
0
        /// <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
        /// </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);
            }

        }
Beispiel #17
0
        /// <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);
            }
        }
Beispiel #18
0
        /// <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);
            }
        }
Beispiel #19
0
 /// <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);
     }
 }
Beispiel #20
0
 public static extern IntPtr ImageList_GetIcon(
     IntPtr himl,
     int i,
     ImageListDrawItemConstants flags);
        private Bitmap GetBitmap(int index, ImageListDrawItemConstants flags)
        {
            var bitmapSize = GetImageListIconSize();
            var bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height);

            using (var g = Graphics.FromImage(bitmap))
            {
                try
                {
                    g.FillRectangle(Brushes.White, new Rectangle(0, 0, bitmapSize.Width, bitmapSize.Height));

                    var hdc = g.GetHdc();

                    var pimldp = new NativeMethods.IMAGELISTDRAWPARAMS { 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.fStyle = (int)flags;

                    if (_iImageList == null || Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA)
                    {
                        NativeMethods.ImageList_DrawIndirect(ref pimldp);
                    }
                    else
                    {
                        _iImageList.Draw(ref pimldp);
                    }
                }
                finally
                {
                    g.ReleaseHdc();
                }


            }

            bitmap.MakeTransparent();
            return bitmap;
        }
Beispiel #22
0
 /// <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);
 }
Beispiel #23
0
        /// <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 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,
            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);
            }
        }
Beispiel #26
0
        /// <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);
        }