-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
68 lines (59 loc) · 2.25 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace FilesPreviewGenerator
{
public partial class Form1 : Form
{
List<FileInfo> files;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
InitData();
gridControl1.DataSource = files;
InitViewSettings();
winExplorerView1.GetThumbnailImage += WinExplorerView_GetThumbnailImage;
}
private void InitData()
{
files = new List<FileInfo>();
string[] fileNames = Directory.GetFiles("Documents\\");
foreach (string item in fileNames)
{
files.Add(new FileInfo(item, Path.GetFileName(item), Path.GetExtension(item)));
}
}
private void InitViewSettings()
{
winExplorerView1.OptionsImageLoad.CacheThumbnails = true;
winExplorerView1.OptionsImageLoad.LoadThumbnailImagesFromDataSource = false;
winExplorerView1.OptionsImageLoad.AsyncLoad = true;
winExplorerView1.OptionsView.Style = DevExpress.XtraGrid.Views.WinExplorer.WinExplorerViewStyle.ExtraLarge;
}
private void WinExplorerView_GetThumbnailImage(object sender, DevExpress.Utils.ThumbnailImageEventArgs e)
{
string filePath = files[e.DataSourceIndex].Path;
string documentFormat = files[e.DataSourceIndex].DocumentFormat;
switch (documentFormat)
{
case ".pdf":
{
int largestEdgeLength = Math.Max(e.DesiredThumbnailSize.Width, e.DesiredThumbnailSize.Height);
e.ThumbnailImage = ImageExporterHelper.GenerateImageFromPDF(filePath, largestEdgeLength);
}
break;
case ".xlsx":
e.ThumbnailImage = ImageExporterHelper.GenerateImageFromExcel(filePath);
break;
case ".docx":
e.ThumbnailImage = ImageExporterHelper.GenerateImageFromWord(filePath);
break;
}
}
}
}