private void FillListBox() { lblFolder.Text = "Files on folder: " + Path.GetDirectoryName(openFileDialog1.FileName); DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(openFileDialog1.FileName)); FileInfo[] Fi = di.GetFiles("*.xls"); FilesListBox.Items.Clear(); TImageInfo[] Files = new TImageInfo[Fi.Length]; for (int k = 0; k < Fi.Length; k++) { FileInfo f = Fi[k]; bool HasCrop = false; bool HasARGB = false; XlsFile x1 = new XlsFile(); bool HasImages = false; try { x1.Open(f.FullName); for (int sheet = 1; sheet <= x1.SheetCount; sheet++) { x1.ActiveSheet = sheet; for (int i = x1.ImageCount; i > 0; i--) { HasImages = true; TImageProperties ip = x1.GetImageProperties(i); if (!HasCrop) { HasCrop = GetHasCrop(ip); } TXlsImgType imgType = TXlsImgType.Unknown; using (MemoryStream ms = new MemoryStream()) { x1.GetImage(i, ref imgType, ms); FlexCel.Pdf.TPngInformation PngInfo = FlexCel.Pdf.TPdfPng.GetPngInfo(ms); if (PngInfo != null) { HasARGB = PngInfo.ColorType == 6; } } } } } catch (Exception) { Files[k] = new TImageInfo(f, false, false, false, false); continue; } Files[k] = new TImageInfo(f, true, HasCrop, HasImages, HasARGB); } FilesListBox.Items.AddRange(Files); }
private void FilesListBox_SelectedIndexChanged(object sender, System.EventArgs e) { TImageInfo ImageInfo = (TImageInfo)FilesListBox.SelectedItem; if (ImageInfo == null) { return; } OpenFile(ImageInfo.File.FullName); }
private void FilesListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if (e.Index < 0) { return; } e.DrawBackground(); Brush myBrush = Brushes.Black; TImageInfo ImageInfo = (TImageInfo)((ListBox)sender).Items[e.Index]; if (!ImageInfo.HasImages) { myBrush = Brushes.Silver; } if (ImageInfo.HasCrop) { myBrush = Brushes.Red; } FontStyle NewStyle; if (ImageInfo.HasARGB) { NewStyle = FontStyle.Bold; } else { NewStyle = FontStyle.Regular; } using (Font MyFont = new Font(e.Font, NewStyle)) { e.Graphics.DrawString(ImageInfo.ToString(), MyFont, myBrush, e.Bounds, StringFormat.GenericDefault); } e.DrawFocusRectangle(); }