Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********
- * SIMPLE IMAGE GALLERY
- * PREV AND NEXT BUTTON
- * BY Okie Eko Wardoyo
- * MediaTutorial.web.id
- * *********/
- 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; //perlu ditambahkan untuk directory
- namespace NEXT_PREVIOUS
- {
- public partial class Form1 : Form
- {
- Bitmap img = null;
- //kita buat variable
- string directoryPath;
- string[] filesArray;
- int totalFiles;
- int i = 0;
- public Form1()
- {
- InitializeComponent();
- }
- private void exitToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void openToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- //kita jadikan mode zoom agar ukuran file fit dengan pictureBox
- pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
- //pictureBox.Load(openFileDialog1.FileName);
- img = new Bitmap(openFileDialog1.FileName);
- pictureBox.Image = img;
- //kita coba mengambil directory dari FileName
- directoryPath = Path.GetDirectoryName(openFileDialog1.FileName);
- //kita coba tampilkan di window output
- Console.WriteLine(directoryPath);
- //mari kita buat array string
- filesArray = Directory.GetFiles(@directoryPath);
- //kita coba tampilkan di window output
- foreach (string file in filesArray)
- {
- Console.WriteLine(file);
- }
- totalFiles = filesArray.Length;
- //kita coba tampilkan di window output
- Console.WriteLine("Total semua = "+totalFiles);
- //kita sekarang akan men-set curent i
- i = Array.IndexOf(filesArray, openFileDialog1.FileName);
- //yuk kita tampilkan curent i di output biar keliatan
- Console.WriteLine("Curent i = " + i);
- }
- }
- private void buttonNext_Click(object sender, EventArgs e)
- {
- if (img != null)
- {
- if (i < totalFiles-1)
- i++;
- img = new Bitmap(filesArray[i]);
- pictureBox.Image = img;
- //kita coba tampilkan di window output
- Console.WriteLine("i = " + i);
- }
- }
- private void buttonPrev_Click(object sender, EventArgs e)
- {
- if (img != null)
- {
- if (i > 0)
- i--;
- img = new Bitmap(filesArray[i]);
- pictureBox.Image = img;
- //kita coba tampilkan di window output
- Console.WriteLine("i = " + i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment