其他分享
首页 > 其他分享> > 9.WinForm练习--图片的上一张和下一张

9.WinForm练习--图片的上一张和下一张

作者:互联网

namespace _9.图片的上一张和下一张
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox1.Image = Image.FromFile(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic\1.jpg");
    }
    //获得图片文件夹的全路径
    string[] path=Directory.GetFiles(@"C:\Users\Administrator.USER-20180925HC\Desktop\pic");
    int i=0;
    private void btnDownPic_Click(object sender, EventArgs e)
    {
       i++;
        if (i == path.Length)
        {
            i = 0;
        }
        pictureBox1.Image = Image.FromFile(path[i]);
    }

    private void btnUpPic_Click(object sender, EventArgs e)
    {
        i--;
        if (i < 0)
        {
            i = path.Length - 1;
        }
        pictureBox1.Image = Image.FromFile(path[i]);
    }
}

}

标签:一张,object,Image,练习,private,pictureBox1,path,void,WinForm
来源: https://blog.51cto.com/12679593/2398255