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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
FolderBrowserDialog repdialog = new FolderBrowserDialog();
string ext = "*.*";
private void detailsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
imageList1.Dispose();
imageList1 = new ImageList();
listView1.GridLines = true;
repdialog.RootFolder = Environment.SpecialFolder.MyPictures;
repdialog.ShowDialog();
DirectoryInfo dir = new DirectoryInfo(repdialog.SelectedPath);
label1.Text = repdialog.SelectedPath;
listView1.View = View.Details;
listView1.Columns.Add("Nom ");
listView1.Columns[0].Width = 300;
listView1.Columns.Add("Taille");
listView1.Columns[1].Width = 100;
listView1.Columns.Add("Date de création ");
listView1.Columns[2].Width = 150;
listView1.Columns.Add("Chemin ");
listView1.Columns[3].Width = 400;
trouve(repdialog.SelectedPath);
listView1.Refresh();
}
catch { }
}
private void grandesIconesToolStripMenuItem_Click_1(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
listView1.Refresh();//
imageList1.Dispose(); imageList1 = new ImageList();
listView1.LargeImageList = imageList1;
listView1.View = View.LargeIcon;
imageList1.ImageSize = new Size(112, 150);
repdialog.RootFolder = Environment.SpecialFolder.MyPictures;
repdialog.ShowDialog();
DirectoryInfo dir = new DirectoryInfo(repdialog.SelectedPath);
label1.Text = repdialog.SelectedPath;
trouve(repdialog.SelectedPath);
listView1.Refresh();
ResetCursor();
}
int j = 0;
private void trouve(string s)
{
try
{
DirectoryInfo dir = new DirectoryInfo(s);
FileInfo[] imageFiles = dir.GetFiles(ext);
foreach (FileInfo f in imageFiles)
{ //**
if (listView1.View == View.List)
{
int i = 0;
ListViewItem item1 = new ListViewItem(f.Name, i);
listView1.Items.Add(item1);
item1.Tag = f.FullName;
i++;
}
else
{ //hors list
if (listView1.View == View.Details)
{ //debut details
int i = 0;
ListViewItem item1 = new ListViewItem(f.Name, i);
item1.ForeColor = Color.DarkBlue;
if (f.Length < 1028) item1.SubItems.Add(f.Length + " oct");
else
{
if (f.Length < 1028 * 1028) item1.SubItems.Add(f.Length / 1028 + " Ko");
else
{
double a = f.Length / (1028.0 * 1028.0);
item1.SubItems.Add(string.Format("{0:##.##}", a) + " Mo");
}
}
item1.UseItemStyleForSubItems = false;
item1.SubItems[1].ForeColor = Color.Black;
item1.SubItems.Add(System.IO.File.GetCreationTime(f.FullName).ToString());
item1.SubItems.Add(f.Directory.ToString());
listView1.Items.Add(item1);
item1.Tag = f.FullName;
i++;
} //fin details
else//grandes et petites icones
{
if (f.Length > 0)
{
using (var fs = File.OpenRead(f.FullName))
{
imageList1.Images.Add(Image.FromStream(fs, true, true));
}
listView1.Items.Add(f.Name, j);
listView1.Items[j].Tag = f.FullName;
j++;
}
}
}//fin hors list
} //fin foreach **
DirectoryInfo[] sousrep = dir.GetDirectories();
foreach (DirectoryInfo rep in sousrep)
{
if (listView1.View == View.Details)
{
ListViewItem itemx = new ListViewItem("");
itemx.SubItems.Add("");
itemx.SubItems.Add("");
listView1.Items.Add(itemx);
itemx = new ListViewItem(rep.FullName);
FileInfo[] g = rep.GetFiles(ext);
if (g.Length != 0)
{
itemx.SubItems[0].BackColor = Color.FromArgb(192, 197, 245);
itemx.SubItems.Add("");
// itemx.UseItemStyleForSubItems = false;
itemx.SubItems.Add("");
listView1.Items[j].Tag = "Repertoire";
itemx.SubItems[0].BackColor = Color.FromArgb(192, 197, 245);
listView1.Items.Add(itemx);
}
}
trouve(rep.FullName);
}
}
catch { }
} |
Partager