Ejemplo n.º 1
0
        void PaintItem(int index, Color color)
        {
            if (index < 0)
            {
                return;
            }
            if (index >= Items.Count)
            {
                return;
            }
            using (Graphics g = Graphics.FromHwnd(Handle))
            {
                int iconindex = sysimagelist.IconIndex(((PIDL)Items[index]).Pidl);
                using (Brush brush = new SolidBrush(color))
                    g.FillRectangle(brush, GetItemRectangle(index));
                g.DrawImage(sysimagelist.Icon(iconindex).ToBitmap(), new Rectangle(8, GetItemRectangle(index).Y + 3, 16, 16));

                if (Items[index].Equals(SelectedItem))
                {
                    using (Font boldfont = new Font(Font.Name, Font.Size, FontStyle.Bold))
                        g.DrawString(Items[index].ToString(), boldfont, Brushes.Black, 36, GetItemRectangle(index).Y + 5);
                }
                else
                {
                    g.DrawString(Items[index].ToString(), Font, Brushes.Black, 36, GetItemRectangle(index).Y + 5);
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            int count = 0;

            Items = new Items();
            if (data != null)
            {
                PIDL pidl = (PIDL)data.Clone();
                while (!pidl.IsDesktop)
                {
                    Items.Add(new Item(pidl));
                    pidl = (PIDL)pidl.GetParentFolder().Clone();
                    count++;
                }
                pidl.DisplayName = "My Computer";
                Item item = Items.Add(new Item(pidl));
                item.Rectangle = new Rectangle(0, 3, 16, 16);
                item.X         = 0;
                item.Y         = 3;
                item.Hotspot   = new Rectangle(17, 3, 17, 16);
                pidl.Dispose();

                int index = sysimagelist.IconIndex(data.Pidl);
                e.Graphics.DrawImage(sysimagelist.Icon(index).ToBitmap(), new Rectangle(3, 3, 16, 16));
                DrawItems(e.Graphics);
            }

            Rectangle rect = ClientRectangle;

            rect.Width--;
            rect.Height--;
            e.Graphics.DrawRectangle(RectPen, rect);
            base.OnPaint(e);
        }
Ejemplo n.º 3
0
 public Icon GetIcon(int index)
 {
     if (m_ImageList == null)
     {
         return(null);
     }
     return(m_ImageList.Icon(index));
 }
Ejemplo n.º 4
0
        void AddImage(IntPtr himage, PIDL pidl, TreeNode item)
        {
            int index = smallimagelist.Images.IndexOfKey(item.Name);

            if (index < 0)
            {
                index = sysimagelist.IconIndex(pidl.Pidl);
                smallimagelist.Images.Add(sysimagelist.Icon(index).ToBitmap());
                index = smallimagelist.Images.Count - 1;
            }
            item.ImageIndex         = index;
            item.SelectedImageIndex = index;
        }
Ejemplo n.º 5
0
        private Bitmap loadJumbo(string lookup)
        {
            _imgList.ImageListSize = isVistaUp() ? SysImageListSize.jumbo : SysImageListSize.extraLargeIcons;
            Icon   icon   = _imgList.Icon(_imgList.IconIndex(lookup, isFolder(lookup)));
            Bitmap bitmap = icon.ToBitmap();

            icon.Dispose();

            System.Drawing.Color empty = System.Drawing.Color.FromArgb(0, 0, 0, 0);

            if (bitmap.Width < 256)
            {
                bitmap = resizeImage(bitmap, new System.Drawing.Size(256, 256), 0);
            }
            else
            if (bitmap.GetPixel(100, 100) == empty && bitmap.GetPixel(200, 200) == empty && bitmap.GetPixel(200, 200) == empty)
            {
                _imgList.ImageListSize = SysImageListSize.largeIcons;
                bitmap = resizeJumbo(_imgList.Icon(_imgList.IconIndex(lookup)).ToBitmap(), new System.Drawing.Size(200, 200), 5);
            }

            return(bitmap);
        }
Ejemplo n.º 6
0
        private Bitmap LoadJumbo(string lookup, TargetType type)
        {
            ImgList.ImageListSize = SysImageJumboSize;
            var icon   = ImgList.Icon(ImgList.IconIndex(lookup, type == TargetType.Folder));
            var bitmap = icon.ToBitmap();

            icon.Dispose();

            var empty = Color.FromArgb(0, 0, 0, 0);

            if (bitmap.Width < 256)
            {
                bitmap = ResizeImage(bitmap, new Size(256, 256), 0);
            }
            else if (bitmap.GetPixel(100, 100) == empty &&
                     bitmap.GetPixel(200, 200) == empty &&
                     bitmap.GetPixel(200, 200) == empty)
            {
                ImgList.ImageListSize = SysImageListSize.LARGE;
                bitmap = ResizeJumbo(ImgList.Icon(ImgList.IconIndex(lookup)).ToBitmap(), new Size(200, 200), 5);
            }

            return(bitmap);
        }
Ejemplo n.º 7
0
        void DrawDesktop(Color color)
        {
            int index = sysimagelist.IconIndex(desktop.Pidl);

            using (Graphics g = Graphics.FromHwnd(desktopPanel.Handle))
                using (Brush brush = new SolidBrush(color))
                {
                    Rectangle rect = desktopPanel.Bounds;
                    rect.X     += 2;
                    rect.Y     += 2;
                    rect.Width -= 4;
                    rect.Height = 20;
                    g.FillRectangle(brush, rect);
                    g.DrawImage(sysimagelist.Icon(index).ToBitmap(), new Rectangle(8, desktopPanel.Bounds.Y + 4, 16, 16));
                    g.DrawString(desktop.DisplayName, Font, Brushes.Black, 35, desktopPanel.Bounds.Y + 6);
                    g.DrawLine(SystemPens.ControlDark, 2, desktopPanel.Height - 5, desktopPanel.Width - 3, desktopPanel.Height - 5);
                }
        }
Ejemplo n.º 8
0
        public static Bitmap GetJumboLargeThumbnail(string fileName)
        {
            Bitmap result;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                try
                {
                    SysImageList sysImageList = new SysImageList(SysImageListSize.SHIL_JUMBO);
                    Bitmap       bitmap       = sysImageList.Icon(sysImageList.IconIndex(fileName, true)).ToBitmap();
                    if (bitmap.GetPixel((int)((double)bitmap.Width / 1.5), (int)((double)bitmap.Height / 1.5)).ToArgb() != 0 && bitmap.GetPixel(bitmap.Width / 2, bitmap.Height / 2).ToArgb() != 0 && bitmap.GetPixel(bitmap.Width / 3, bitmap.Height / 3).ToArgb() != 0 && bitmap.GetPixel(bitmap.Width / 4, bitmap.Height / 4).ToArgb() != 0)
                    {
                        result = bitmap;
                        return(result);
                    }
                    SysImageList sysImageList2 = new SysImageList(SysImageListSize.extraLargeIcons);
                    Bitmap       bitmap2       = sysImageList2.Icon(sysImageList2.IconIndex(fileName, true)).ToBitmap();
                    result = bitmap2;
                    return(result);
                }
                catch (Exception)
                {
                    result = null;
                    return(result);
                }
            }
            if (Environment.OSVersion.Version.Major >= 5)
            {
                try
                {
                    SysImageList sysImageList2 = new SysImageList(SysImageListSize.extraLargeIcons);
                    result = sysImageList2.Icon(sysImageList2.IconIndex(fileName, true)).ToBitmap();
                    return(result);
                }
                catch (Exception)
                {
                    result = null;
                    return(result);
                }
            }
            result = null;
            return(result);
        }
Ejemplo n.º 9
0
        void AddImage(IntPtr himage, PIDL pidl, ListViewItem item)
        {
            int    imageSize = largeimagelist.ImageSize.Width;
            Bitmap bmp       = null;

            //if (thumbDB.HasThumbnail(System.IO.Path.GetFileName(pidl.PhysicalPath)))
            //{
            //    using (Image img = thumbDB.GetThumbnailImage(System.IO.Path.GetFileName(pidl.PhysicalPath)))
            //    {
            //        largeimagelist.Images.Add(item.Name, Thumbnail.ScaleImage((Bitmap)img, imageSize, imageSize));
            //        item.ImageIndex = largeimagelist.Images.Count - 1;

            //        return;
            //    }

            //}
            try
            {
                if (largeimagelist.Images.IndexOfKey(item.Name) < 0)
                {
                    if (himage == IntPtr.Zero)
                    {
                        switch (imageSize)
                        {
                        case 16: sysimagelist = new SysImageList(SysImageListSize.smallIcons); break;

                        case 48: sysimagelist = new SysImageList(SysImageListSize.largeIcons); break;

                        case 96: sysimagelist = new SysImageList(SysImageListSize.extraLargeIcons); break;

                        case 256: sysimagelist = new SysImageList(SysImageListSize.JumboIcons); break;
                        }
                        int index = sysimagelist.IconIndex(pidl.Pidl);
                        LargeImageList.Images.Add(item.Name, Thumbnail.CreateAlphaBitmap(sysimagelist.Icon(index).ToBitmap(), System.Drawing.Imaging.PixelFormat.Format32bppArgb));

                        smallimagelist.Images.Add(item.Name, Thumbnail.CreateAlphaBitmap(sysimagelist.Icon(index).ToBitmap(), System.Drawing.Imaging.PixelFormat.Format32bppArgb));
                        item.ImageIndex = LargeImageList.Images.Count - 1;
                    }
                    else
                    {
                        //bmp = Thumbnail.GetCachedImage(pidl.Pidl, imageSize);
                        //if (bmp == null)
                        {
                            bmp = Thumbnail.GetBitmapFromHBitmap(himage);
                            {
                                smallimagelist.Images.Add(item.Name, Thumbnail.CentreImage(bmp, smallimagelist.ImageSize.Width, smallimagelist.ImageSize.Height));
                                if ((bmp.Width != imageSize && bmp.Height != imageSize))// && pidl.PhysicalPath != "")
                                {
                                    bmp = Thumbnail.CentreImage(bmp, imageSize, imageSize);
                                }
                                else
                                {
                                    if (bmp.Width != imageSize || bmp.Height != imageSize)
                                    {
                                        bmp = Thumbnail.ScaleImage(bmp, imageSize, imageSize);
                                    }
                                }
                            }
                            //Thumbnail.SaveThumb(pidl.Pidl, bmp);
                        }
                        largeimagelist.Images.Add(item.Name, bmp);

                        item.ImageIndex = largeimagelist.Images.Count - 1;
                    }
                    return;
                }
                item.ImageIndex = largeimagelist.Images.IndexOfKey(item.Name);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (bmp != null)
                {
                    bmp.Dispose();
                }
                Thumbnail.DeleteObject(himage);
            }
        }