首页 > Windows开发 > 详细

Chapter 3.WinForm(PictureBox控件)

时间:2016-06-30 18:05:16      阅读:353      评论:0      收藏:0      [点我收藏+]

技术分享

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;

namespace 图片控件
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //设置图片显示方式:平铺
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            
            //获得指定一种图片的路径
            pictureBox1.Image = Image.FromFile(@"C:\Users\Administrator\Desktop\新建文件夹\1.jpg");
        }

        int i = 0;

        //获得指定文件夹中的所有文件路径
        string[] path = Directory.GetFiles(@"C:\Users\Administrator\Desktop\新建文件夹");

        /// <summary>
        /// 点击更换下一张图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            i++;
            if (i == path.Length)
            {
                i = 0;
            }
            pictureBox1.Image = Image.FromFile(path[i]);
        }

        /// <summary>
        /// 点击更换上一张图片
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            i--;
            if(i<0)
            {
                i = path.Length - 1;
            }
            pictureBox1.Image = Image.FromFile(path[i]);
        }
    }
}

技术分享技术分享

技术分享

 

Chapter 3.WinForm(PictureBox控件)

原文:http://www.cnblogs.com/xiao55/p/5630398.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!