Пример #1
0
        /// <summary>
        /// create DWG thumnails from an folder with dwg file and dwg file thumanil below it
        /// the number of dwg file and dwg file thumanil must be the same
        /// </summary>
        /// <param name="Path">The path of an folder</param>
        /// <returns></returns>
        private List <DwgThumnail> CreateDwgThumnails(string Path)
        {
            List <DwgThumnail> DwgThumnailList = new List <DwgThumnail>();
            List <string>      Files           = Directory.GetFiles(Path, "*.dwg", SearchOption.AllDirectories).ToList();
            int type = 0;

            if (Regex.Match(Path, @"StdBlock").Success)
            {
                type = 0;
            }
            else
            {
                type = 1;
            }
            //使用并行的方法来创建DwgThumnail
            if (Files.Count == 0)
            {
                return(DwgThumnailList);
            }
            Parallel.ForEach(Files, File =>
            {
                DwgThumnail DwgItem = new DwgThumnail(File, type);
                DwgThumnailList.Add(DwgItem);
            });
            return(DwgThumnailList);
        }
Пример #2
0
        private static void InitLibrary(PaletteSet myPaletteSet)
        {
            string libraryPath;

            if (GetLibPath() != "")
            {
                libraryPath = GetLibPath();
            }
            else
            {
                MessageBox.Show("无法加载图库文件,请指定正确的图库加载路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string[] strArr = Directory.GetDirectories(libraryPath);
            for (int i = 0; i < strArr.Length; i++)
            {
                Panel  customPanel = new Panel();
                string paletteName = Path.GetFileNameWithoutExtension(strArr[i]);

                myPaletteSet.Add(paletteName, customPanel);
                string[] strArr2 = Directory.GetDirectories(strArr[i]);

                if (strArr2.Length != 0)
                {
                    TabControl Tab = new TabControl();
                    Tab.Dock = DockStyle.Fill;
                    for (int j = 0; j < strArr2.Length; j++)
                    {
                        string  tabName = Path.GetFileNameWithoutExtension(strArr2[j]);
                        TabPage tabPage = new TabPage(tabName);
                        Tab.Multiline = true;
                        Tab.Controls.Add(tabPage);

                        FlowLayoutPanel floatPanel = new FlowLayoutPanel();

                        floatPanel.Dock          = DockStyle.Fill;
                        floatPanel.FlowDirection = System.Windows.Forms.FlowDirection.LeftToRight;

                        Panel panel = new Panel();
                        panel.Dock       = DockStyle.Fill;
                        panel.BackColor  = Color.White;
                        panel.AutoScroll = true;

                        panel.Controls.Add(floatPanel);
                        tabPage.Controls.Add(panel);
                        panel.Padding = new Padding(20, 20, 20, 20);
                        string[] filePath = Directory.GetFiles(strArr2[j]);
                        if (filePath.Length != 0)
                        {
                            List <Control> ItemList = new List <Control>();
                            for (int k = 0; k < filePath.Length; k++)
                            {
                                string FileExtension = Path.GetExtension(filePath[k]).ToLower();
                                string FileName      = Path.GetFileNameWithoutExtension(filePath[k]);
                                string Directory     = Path.GetDirectoryName(filePath[k]);

                                if (FileExtension == ".jpg")
                                {
                                    DwgThumnail item = new DwgThumnail();
                                    item.Width                    = 70;
                                    item.Height                   = 80;
                                    item.filePath                 = Directory + "/" + FileName + ".dwg";
                                    item.FileName.Text            = FileName;
                                    item.Thumnail.Height          = 60;
                                    item.Thumnail.Width           = 70;
                                    item.Thumnail.BackgroundImage = Bitmap.FromFile(filePath[k]);
                                    floatPanel.Controls.Add(item);
                                }
                            }
                        }
                    }
                    customPanel.Controls.Add(Tab);
                }
                else
                {
                    string[] filePath = Directory.GetFiles(strArr[i]);
                    if (filePath.Length != 0)
                    {
                        FlowLayoutPanel floatPanel = CreateFloatLayoutPanel();
                        floatPanel.AutoScroll = true;
                        floatPanel.Dock       = DockStyle.Fill;
                        floatPanel.Padding    = new Padding(20, 20, 20, 20);
                        customPanel.Controls.Add(floatPanel);
                        for (int k = 0; k < filePath.Length; k++)
                        {
                            string FileExtension = Path.GetExtension(filePath[k]).ToLower();
                            string FileName      = Path.GetFileNameWithoutExtension(filePath[k]);
                            string Directory     = Path.GetDirectoryName(filePath[k]);
                            if (FileExtension == ".jpg")
                            {
                                DwgThumnail item = new DwgThumnail();
                                item.Width                    = 70;
                                item.Height                   = 80;
                                item.filePath                 = Directory + "/" + FileName + ".dwg";
                                item.FileName.Text            = FileName;
                                item.Thumnail.Height          = 60;
                                item.Thumnail.Width           = 70;
                                item.Thumnail.BackgroundImage = Bitmap.FromFile(filePath[k]);
                                floatPanel.Controls.Add(item);
                            }
                        }
                    }
                }
            }
        }