I am trying to make a slide show application in C#. So far I have it working, but what I am having trouble with is when a new photo is dropped into the selected directory. The photo isnt picked up and added to the the sideshow list. The application is designed to be left alone all day and the end user doesn't want to restart the application each time they add a photo. What ideally should happen is the when they add a photo, the slide show continues to the end and then restarts from the beginning but this time includes the photo that was added.
I have tried to set the timer to recheck the images in the directory each time the images reach the end of sildeshow but am not having much luck.
Any suggestions?
My code is below.
Thanks
Carl
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace PullManSlideShow
{
public partial class Form1 : Form
{
int fileMax = 0;
int fileCount = 0;
public Form1()
{
InitializeComponent();
}
string[] pictureLocationBoxArray = new string[100];
FolderBrowserDialog pictureSelection = new FolderBrowserDialog();
public void ImageIdentification(string a) //passes in all the locations of the files
{
//checks to see if is suitable type
if ((a.EndsWith(".jpg")) || (a.EndsWith(".png")) || (a.EndsWith(".gif")) || (a.EndsWith(".jpeg")) || (a.EndsWith(".bmp"))
|| (a.EndsWith(".JPG")) ||(a.EndsWith(".JPEG")) || (a.EndsWith(".GIF")) || (a.EndsWith(".PNG")) || (a.EndsWith(".BMP")))
{
pictureLocationBoxArray[fileMax] = a;//stores location of images
//MessageBox.Show(a);
Image im = Image.FromFile(a);
PictureBox pb = new PictureBox();
pb.Image = im;
panel1.Controls.Add(pb);
fileMax++;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (fileCount == fileMax)
{
fileCount = 0;
////////////////////////
// this is possible solution but doesnt seem to work
string tempString = "";
int stringLength = 0;
tempString = pictureLocationBoxArray[fileCount];
stringLength = tempString.Length;
tempString = tempString.Substring(0, (stringLength - 8));
// -8 becuase 000.jpeg is 8 letters, possible peoblem if 000.gif etc
// Images are labelled like 000.jpeg where 0s are numbers. eg 001.jpeg is the first images shown, 019.jpeg is
// second. If a new image is added say 005.jpeg it will now come second on the list 001.jpeg,005.jpeg,019,jpeg etc
// Get updated list of files
//string[] images = Directory.GetFiles(tempString);
panel1.Controls.Clear();
foreach (string a in Directory.GetFiles(tempString))
{
ImageIdentification(a);
}
}
PictureBox p = (PictureBox) panel1.Controls[fileCount];
pictureBox1.Image = p.Image;
fileCount++;
}
private void Form1_Load(object sender, EventArgs e)
{
fileMax = 0;
//panel1.Controls.Clear();
if (pictureSelection.ShowDialog() == DialogResult.OK)
{
foreach (string a in Directory.GetFiles(pictureSelection.SelectedPath))
{
ImageIdentification(a);
}
timer1.Enabled = true;
}
}
}
}

New Topic/Question
Reply



MultiQuote







|