Пример #1
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);
                }
        }
Пример #2
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);
        }
Пример #3
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);
            }
        }
Пример #4
0
        private void ReadDirectory(IList <ArchiveFileInfo> archiveFileInfos, TreeNode parentNode, int level)
        {
            lvArchiveDetails.Tag = archiveFileInfos;
            lvArchiveDetails.BeginUpdate();
            for (int i = 0; i < archiveFileInfos.Count; i++)
            {
                var Splittedname = archiveFileInfos[i].FileName.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
                if (Splittedname.Length == 1)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi.Text = Path.GetFileNameWithoutExtension(Splittedname[0]);
                    lvi.Tag  = archiveFileInfos[i].FileName;
                    if (archiveFileInfos[i].IsDirectory)
                    {
                        lvi.ImageIndex = lst.IconIndex(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup), true);
                        lvi.SubItems.Add("Folder");
                    }
                    else
                    {
                        lvi.ImageIndex = lst.IconIndex(Path.GetExtension(archiveFileInfos[i].FileName));
                        lvi.SubItems.Add("File");
                    }


                    lvArchiveDetails.Items.Add(lvi);
                }
            }
            lvArchiveDetails.EndUpdate();

            //for (int j = 0; j < archiveFileInfos.Count;j++)
            //{
            //    var childNode = new TreeNode();
            //    var names = archiveFileInfos[j].FileName.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            //    childNode.Text = names[level];
            //    childNode.Tag = archiveFileInfos[j];



            //    if (archiveFileInfos[j].IsDirectory)
            //    {
            //        var fileInfos = new List<ArchiveFileInfo>();
            //        foreach(var fileInfo in archiveFileInfos)
            //        {
            //            var testnames = fileInfo.FileName.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
            //            if (testnames.Length - 1 < level + 1)
            //            {
            //                continue;
            //            }
            //            for (int i = 0; i <= level; i++)
            //            {
            //                if (testnames[i] != names[i])
            //                {
            //                    continue;
            //                }
            //            }
            //            fileInfos.Add(fileInfo);
            //        }
            //        ReadDirectory(fileInfos, childNode, level + 1);

            //        //childNode.ImageIndex = 3;
            //        j += fileInfos.Count;
            //    }
            //    //else
            //    //{
            //    //    childNode.ImageIndex = SelectImageIndex(names[names.Length -1]);
            //    //}


            //    parentNode.Nodes.Add(childNode);
            //}
        }
Пример #5
0
 public int GetIconIndex(string fileName)
 {
     return(m_ImageList == null ? -1 : m_ImageList.IconIndex(fileName));
 }