GetFileIcon() публичный статический Метод

public static GetFileIcon ( string fileName, bool isLargeIcon ) : Icon
fileName string
isLargeIcon bool
Результат System.Drawing.Icon
Пример #1
0
        //显示文件列表
        private void ShowInListView(List <FileInfoModel> floderlist)
        {
            List <string> fileExtensionDic = new List <string>();
            ImageList     filesImageList   = new ImageList();

            lvFiles.Items.Clear();
            if (floderlist.Count > 0)
            {
                //int indexI = 0;
                List <ListViewItem> listBuffer = new List <ListViewItem>();
                foreach (var item in floderlist)
                {
                    string fileExtension = MkFileType(item);
                    if (!fileExtensionDic.Contains(fileExtension))
                    {
                        fileExtensionDic.Add(fileExtension);
                        filesImageList.ColorDepth = ColorDepth.Depth32Bit;
                        filesImageList.Images.Add(SystemFileHelper.GetFileIcon(fileExtension, false));
                    }

                    string fileName = item.FileName;
                    if (fileName == ".Trash")
                    {
                        continue;
                    }
                    ListViewItem li = new ListViewItem();
                    li.ImageIndex       = fileExtensionDic.IndexOf(fileExtension);
                    li.SubItems[0].Text = fileName;
                    li.SubItems.Add(item.Modification_time == 0 ? "" : DateTime.FromFileTimeUtc(item.Modification_time).ToString("yyyy-MM-dd HH:mm"));
                    li.SubItems.Add(fileExtension);
                    li.SubItems.Add(item.Isdir ? "" : MkFileSize(item.Size));
                    li.Tag = item;
                    listBuffer.Add(li);

                    //if (indexI++ % 1000 == 0)
                    //{
                    //    lvFiles.Items.AddRange(listBuffer.ToArray());
                    //    listBuffer.Clear();
                    //}
                    //Application.DoEvents();
                }
                lvFiles.Items.AddRange(listBuffer.ToArray());
                listBuffer = null;

                lvFiles.SmallImageList = filesImageList;

                mystatusbar.ImageList = filesImageList;
                lbFileInfo.ImageIndex = 0;
                lbFileInfo.Text       = floderlist.Count + " 对象";
            }
            else
            {
                lvFiles.Items.Add(new ListViewItem()
                {
                    Text = "该文件夹为空。"
                });
            }
            lbProgressTxt.Text = "";
        }
Пример #2
0
        //显示文件列表
        private void ShowInListView(List <FileStatus> floderlist)
        {
            List <string> fileExtensionDic = new List <string>();
            ImageList     filesImageList   = new ImageList();

            lvFiles.Items.Clear();
            if (floderlist.Count > 0)
            {
                int indexI = 0;
                List <ListViewItem> listBuffer = new List <ListViewItem>();
                foreach (FileStatus item in floderlist)
                {
                    string fileExtension = MkFileType(item);
                    if (!fileExtensionDic.Contains(fileExtension))
                    {
                        fileExtensionDic.Add(fileExtension);
                        filesImageList.Images.Add(
                            SystemFileHelper.GetFileIcon(fileExtension, false));
                    }

                    string fileName = HideRootName(item.Path);
                    if (fileName == ".Trash")
                    {
                        continue;
                    }
                    ListViewItem li = new ListViewItem();
                    li.ImageIndex       = fileExtensionDic.IndexOf(fileExtension);
                    li.SubItems[0].Text = fileName;
                    li.SubItems.Add(new DateTime(1970, 1, 1).AddMilliseconds(item.Modification_time).AddHours(8).ToString("yyyy-MM-dd HH:mm"));
                    li.SubItems.Add(fileExtension);
                    li.SubItems.Add(item.Isdir ? "" : MkFileSize(item.Length));
                    li.Tag = item;
                    listBuffer.Add(li);

                    if (indexI++ % 1000 == 0)
                    {
                        lvFiles.Items.AddRange(listBuffer.ToArray());
                        listBuffer.Clear();
                    }
                    Application.DoEvents();
                }
                lvFiles.Items.AddRange(listBuffer.ToArray());
                lvFiles.SmallImageList = filesImageList;

                mystatusbar.ImageList = filesImageList;
                lbFileInfo.ImageIndex = 0;
                lbFileInfo.Text       = floderlist.Count + " 对象";
            }
            else
            {
                lvFiles.Items.Add(new ListViewItem()
                {
                    Text = "该文件夹为空。"
                });
            }
        }