Example #1
0
        public FileBrowser(string title, string ext = "", FilterType filterType = null, Icon icon = null, FilterType selectableType = null)
        {
            if (null == filterType)
            {
                filterType = FilterType.ANY;
            }

            InitializeComponent();

            try
            {
                this.Text  = title;
                Ext        = ext;
                FilterType = filterType;
                if (selectableType == null)
                {
                    SelectableType = FilterType.DIR;
                }
                else
                {
                    SelectableType = selectableType;
                }
                if (icon != null)
                {
                    this.Icon = icon;
                }

                // 初始化ImageList
                imgLst.Images.AddRange(FileBrowserImg.GetAllImgs().ToArray());
                tvFile.ImageList = imgLst;

                InitEvent();
            }
            catch (Exception ex)
            {
                Logger.WriteEx2LogFile(ex);
            }
        }
Example #2
0
        private List <TreeNode> BindData(List <FileTreeNodeInfo> fileTreeNodeInfos, bool isRoot = false)
        {
            List <TreeNode> treeNodes = new List <TreeNode>();

            foreach (FileTreeNodeInfo fileTreeNodeInfo in fileTreeNodeInfos)
            {
                TreeNode treeNode = null;
                if (isRoot)
                {
                    treeNode = new TreeNode()
                    {
                        Text               = fileTreeNodeInfo.Name,
                        Name               = fileTreeNodeInfo.Path,
                        ImageIndex         = FileBrowserImg.DRIVER.Value,
                        SelectedImageIndex = FileBrowserImg.DRIVER.Value
                    };
                }
                else
                {
                    if (fileTreeNodeInfo.FileTreeNodeType == 0)
                    {
                        if (FilterType.Value != WinFormController.FilterType.DIR.Value)
                        {
                            if (!Str.IsNullOrWhiteSpace(Ext))
                            {
                                string[] exts = Ext.Split('|');
                                if (Str.IsMatch(fileTreeNodeInfo.Path, exts, MatchType.SUFFIX))
                                {
                                    continue;
                                }
                            }

                            int imgIndex = FileBrowserImg.GetValueByStr(fileTreeNodeInfo.Path);
                            treeNode = new TreeNode()
                            {
                                Text               = fileTreeNodeInfo.Name,
                                Name               = fileTreeNodeInfo.Path,
                                ImageIndex         = imgIndex,
                                SelectedImageIndex = imgIndex
                            };
                        }
                    }
                    else
                    {
                        treeNode = new TreeNode()
                        {
                            Text               = fileTreeNodeInfo.Name,
                            Name               = fileTreeNodeInfo.Path,
                            ImageIndex         = FileBrowserImg.DIR.Value,
                            SelectedImageIndex = FileBrowserImg.DIR_OPEN.Value
                        };
                    }
                }

                foreach (FileTreeNodeInfo item in fileTreeNodeInfo.ChildDirs)
                {
                    TreeNode childTreeNode = null;
                    if (item.FileTreeNodeType == 0)
                    {
                        // 文件
                        if (FilterType.Value != FilterType.DIR.Value)
                        {
                            if (!Str.IsNullOrWhiteSpace(Ext))
                            {
                                string[] exts = Ext.Split('|');
                                if (Str.IsMatch(item.Path, exts, MatchType.SUFFIX))
                                {
                                    continue;
                                }
                            }

                            int imgIndex = FileBrowserImg.GetValueByStr(item.Path);
                            childTreeNode = new TreeNode()
                            {
                                Text               = item.Name,
                                Name               = item.Path,
                                ImageIndex         = imgIndex,
                                SelectedImageIndex = imgIndex
                            };
                        }
                    }
                    else
                    {
                        // 文件夹
                        childTreeNode = new TreeNode()
                        {
                            Text               = item.Name,
                            Name               = item.Path,
                            ImageIndex         = FileBrowserImg.DIR.Value,
                            SelectedImageIndex = FileBrowserImg.DIR_OPEN.Value
                        };
                    }
                    if (null != childTreeNode)
                    {
                        treeNode.Nodes.Add(childTreeNode);
                    }
                }
                if (treeNode != null)
                {
                    treeNodes.Add(treeNode);
                }
            }

            return(treeNodes);
        }