C # implements the previous and next page features

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.