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
|
// Index de l'image courante
private int CurrentIndex = 0;
// Liste des images du dossier
private List<String> PictureFiles;
// Initialisation
private void Form1_Load(object sender, System.EventArgs e)
{
SearchPictureFiles(@"D:\temp");
LoadCurrentPicture();
}
// Recherche de la liste des fichiers image (jpg et bmp) du dossier envoyé en paramètres.
private void SearchPictureFiles(String Path)
{
PictureFiles = Directory.GetFiles(Path, "*.*", SearchOption.TopDirectoryOnly)
.Where(s => s.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase) ||
s.EndsWith(".jpg",StringComparison.OrdinalIgnoreCase) ||
s.EndsWith(".png",StringComparison.OrdinalIgnoreCase))
.ToList();
}
// Charge l'image courante
private void LoadCurrentPicture()
{
if ((CurrentIndex >= 0) && (CurrentIndex < PictureFiles.Count))
myPictureBox.ImageLocation = PictureFiles.ElementAt(CurrentIndex);
}
// Image suivante ou première image
private void btNext_Click(object sender, System.EventArgs e)
{
if (CurrentIndex < PictureFiles.Count - 1)
CurrentIndex++;
else
CurrentIndex = 0;
LoadCurrentPicture();
}
// Image précédente ou dernière image
private void btPrevious_Click(object sender, System.EventArgs e)
{
if (CurrentIndex > 0)
CurrentIndex--;
else
CurrentIndex = PictureFiles.Count - 1;
LoadCurrentPicture();
} |
Partager