/// <summary> /// /// </summary> private void RemoveDwgThumnailFromPanel() { if (this.ItemLayoutPanel.Controls.Count != 0) { this.ItemLayoutPanel.SuspendLayout(); ControlCollection ControlCollect = this.ItemLayoutPanel.Controls; //this.ItemLayoutPanel.Controls.Clear(); while (ControlCollect.Count != 0) { DwgThumnail item1 = ControlCollect[0] as DwgThumnail; Label item2 = ControlCollect[0] as Label; if (item1 != null) { this.ItemLayoutPanel.Controls.Remove(item1); item1.Dispose(true); } else { this.ItemLayoutPanel.Controls.Remove(item2); item2.Dispose(); } } this.ItemLayoutPanel.ResumeLayout(); } }
/// <summary> /// /// </summary> /// <param name="DWGFilePath"></param> /// <param name="FileName"></param> /// <param name="ThunmailPath"></param> /// <returns></returns> private DwgThumnail CreateDWGThumnail(string DWGFilePath, string FileName, string ThunmailPath) { DwgThumnail Item = new DwgThumnail(); Item.filePath = DWGFilePath; Item.Width = 80; Item.Height = 90; Item.Thumnail.Width = 70; Item.Thumnail.Height = 60; Item.FileName.Text = FileName; Item.Thumnail.BackgroundImage = Bitmap.FromFile(ThunmailPath); return(Item); }
/// <summary> /// /// </summary> /// <param name="PathStr"></param> private void AddDwgThumnailToPanel(string PathStr) { if (!Directory.Exists(PathStr)) { MessageBox.Show("文件路径不正确"); return; } this.RemoveDwgThumnailFromPanel(); List <DwgThumnail> ThumnailCollect = new List <DwgThumnail>(); string[] FilesArr = Directory.GetFiles(PathStr, "*.jpg", SearchOption.AllDirectories); if (FilesArr.Length == 0) { string Text = "文件夹中不包含有CAD缩略图"; this.ItemLayoutPanel.Controls.Add(this.CreateLabelText(Text, StateLevel.Warrning)); this.Statusbar.Text = Text; } else { this.ItemLayoutPanel.SuspendLayout(); //并行运算速度更快 Parallel.ForEach(FilesArr, item => { string FileName = Path.GetFileNameWithoutExtension(item); string DWGFilePath = item.Replace(".jpg", ".dwg"); DwgThumnail Item = this.CreateDWGThumnail(DWGFilePath, FileName, item); ThumnailCollect.Add(Item); }); /* * for (int Index = 0; Index < FilesArr.Length; Index++) * { * string FileName = Path.GetFileNameWithoutExtension(FilesArr[Index]); * string DWGFilePath = FilesArr[Index].Replace(".jpg",".dwg"); * DwgThumnail Item = this.CreateDWGThumnail(DWGFilePath, FileName, FilesArr[Index]); * ThumnailCollect.Add(Item); * }*/ this.ItemLayoutPanel.Controls.AddRange(ThumnailCollect.ToArray()); this.ItemLayoutPanel.ResumeLayout(); } }