public void SetFlowLayout(string path) { if (!Directory.Exists(path)) { return; } this.flowLayoutPanel_ThematicDoc.Controls.Clear(); DirectoryInfo di = new DirectoryInfo(path); FileSystemInfo[] files = di.GetFileSystemInfos(); try { for (int i = 0; i < files.Length; i++) { //如果不是文件 if (files[i] is FileInfo) { FileInfo file = files[i] as FileInfo; string ext = file.Extension; if (ext.ToLower() != ".doc" && ext.ToLower() != ".docx") continue; string title = Path.GetFileNameWithoutExtension(file.FullName); ucGalleryItemDoc gi = new ucGalleryItemDoc(); gi.Title = title; gi.HoverImagePath = clsConfig.GetThumbFolder(path) + "\\" + title + ".jpg"; gi.Size = new Size(this.flowLayoutPanel_ThematicDoc.Size.Width - 20, gi.Size.Height); gi.DataPath = file.FullName; gi.delegateGalleryItemDocClick += new delegateGalleryItemDocClick(gi_Click); gi.delegateGalleryItemDocMouseEnter += new delegateGalleryItemDocMouseEnter(gi_MouseEnter); gi.delegateGalleryItemDocMouseLeave += new delegateGalleryItemDocMouseLeave(gi_MouseLeave); this.flowLayoutPanel_ThematicDoc.Controls.Add(gi); } } } catch { } }
void gi_MouseEnter(ucGalleryItemDoc ucgi) { if (ucgi != null) { if (!File.Exists(ucgi.HoverImagePath)) { return; } Image img = Image.FromFile(ucgi.HoverImagePath); this.pic_PreView.BackgroundImage = img; this.lbl_PreViewMapTitle.Text = ucgi.Title; } }
void gi_MouseLeave(ucGalleryItemDoc ucgi) { this.pic_PreView.BackgroundImage = null; this.lbl_PreViewMapTitle.Text = ""; }
void gi_Click(ucGalleryItemDoc ucgi) { frmDocViewer frmDoc = new frmDocViewer(this); frmDoc.DocPath = ucgi.DataPath; this.Visible = false; frmDoc.Show(); }