I'm writing a program that open a folderBrowserDialog1
and then loop through the files in a directory using
using string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories);
to get all the files in the folder and the sub folders, later on the program split the array of strings into multiple lists, that filters the data to 4 types
public static readonly List<string> ImageExtensions = new List<string> { ".JPG", ".JPE", ".BMP", ".GIF", ".PNG" };
public static readonly List<string> OfficeExtensions = new List<string> { ".DOC", ".DOCX", ".XLS", ".XLSX", ".PPT",".PPTX",".XLM",".PPS",".PPSX",".MDB" };
public static readonly List<string> VideoExtensions = new List<string> { ".FLV", ".AVI", ".MOV", ".MP4", ".MPG", ".WMV", ".3GP", ".ASF", ".RM", ".SWF",".MTS" };
public static readonly List<string> AudioExtensions = new List<string> { ".AAC", ".MP3", ".OGG", ".WMA", ".WAV" };
public static List<string> images = new List<string>();
public static List<string> audio = new List<string>();
public static List<string> videos = new List<string>();
I'm taking the pictures to display them in thumbs in another form code is the following:
public partial class frm_brsimag : MainForm
{
public static List<string> selimages = new List<string>();
int currPos = 0;
const int pageCount = 100;
public frm_brsimag()
{
InitializeComponent();
}
private void frm_brsimag_Load(object sender, EventArgs e)
{
menuStrip1.Hide();
}
private void LoadImages(int startFrom, int to)
{
flowLayoutPanel1.Controls.Clear();
for (int file = startFrom; file < startFrom + to; file++)
{
LinkLabel l = new LinkLabel();
l.Tag = FileManager.images[file];
l.Text = Path.GetFileNameWithoutExtension(FileManager.images[file]);
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
PictureBox picBox = new PictureBox();
picBox.SizeMode = PictureBoxSizeMode.StretchImage;
picBox.ContextMenuStrip = contextMenuStrip1;
picBox.Height = 125;
picBox.Width = 125;
picBox.LoadAsync(FileManager.images[file]);
//Label lbl = new Label();
// lbl.Text = Path.GetFileNameWithoutExtension(FileManager.images[file]);
flowLayoutPanel1.Controls.Add(picBox);
flowLayoutPanel1.Controls.Add(l);
l.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkedLabelClicked);
//flowLayoutPanel1.Controls.Add(lbl);
}
}
private void LinkedLabelClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string filepath = ((LinkLabel)sender).Tag.ToString();
Process.Start("explorer.exe", "/select," + filepath);
}
private void btnNext_Click(object sender, EventArgs e)
{
if (FileManager.images.Count - currPos > pageCount)
{
LoadImages(currPos, pageCount);
currPos += pageCount;
}
else
{
LoadImages(currPos, FileManager.images.Count - currPos);
currPos += FileManager.images.Count - currPos;
}
}
private void btnPrev_Click(object sender, EventArgs e)
{
if (currPos >= pageCount)
currPos -= pageCount;
else
currPos = 0;
LoadImages(currPos, pageCount);
}
The problem is: I have a big number of files do deal with like 35K of pics sometimes.
I tried to make a next
and previous
button that load the pictures 100 by 100 in the form as the picture shows, to prevent the app from consuming a lot of space from memory, but its not working, when I load the program with the pictures task manager showed that the program consumed 1.2 GB, and when I press the next
button, it keeps on increasing can you help out, and after many page navigation the program crashed, thanks!
design of the forum so i makes things clear: https://i.stack.imgur.com/gdOYO.jpg