public partial class Form1:form
{
Private string[] filelists = null;//definition filelist collection is used to store all files in the current file
private string fileName = "";//the name of the picture selected after the user pops up the dialog box
Public Form1 ()
{
InitializeComponent ();
}
<summary>
Get a picture resource from your local disk
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
private void Btnopenimg_click (object sender, EventArgs e)
{
OpenFileDialog Opendlg = new OpenFileDialog ();
Opendlg.filter = "Picture resource (*.png) |*.png| picture resource (*.jpg) |*.jpg| All Files (*. *) |*.*";
Opendlg.showdialog ();
FileName = Opendlg.filename;
MessageBox.Show ("filename=" + fileName);
String path = Path.getdirectoryname (FileName);
MessageBox.Show (path);
filelists = directory.getfiles (path);//Get all files under this path
This.pictureBox1.Image = Image.FromFile (@fileName);
}
private void Form1_Load (object sender, EventArgs e)
{
This.pictureBox1.SizeMode = pictureboxsizemode.stretchimage;//Sets the display mode of the picture
}
int index = 0;
BOOL Ishasindex = false;
private void Btnlastimage_click (object sender, EventArgs e)
{
if (filelists = = null)
{
MessageBox.Show ("Please select a picture");
}
Else
{
if (!ishasindex)
{
for (int i = 0; i < filelists.length; i++)
{
if (FileName = = Filelists[i])
{
index = i;//assigns a value to indexes
MessageBox.Show ("index=" + index);
Ishasindex = true;
}
}
}
if (index = = 1)
{
index = filelists.length;
}
This.pictureBox1.Image = Image.FromFile (filelists[index-1]);
index--;
}
}
private void Btnnextimage_click (object sender, EventArgs e)
{
if (filelists = = null)
{
MessageBox.Show ("Please select a picture");
}
Else
{
if (!ishasindex)
{
for (int i = 0; i < filelists.length; i++)
{
if (FileName = = Filelists[i])
{
index = i;//assigns a value to indexes
MessageBox.Show ("index=" + index);
Ishasindex = true;
}
}
}
if (index = = filelists.length-1)
{
index = 1;
}
This.pictureBox1.Image = Image.FromFile (filelists[index+1]);
index++;
}
}
}
C # implements the previous and next page features