winform学习之----图片控件应用(上一张,下一张)

示例1:   

        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]);
            
        }
        //上一张图片
        private void button1_Click(object sender, EventArgs e)
        {
            i--;
            if (i < 0)
            {
                i = path.Length - 1;
            }
            pictureBox1.Image = Image.FromFile(path[i]);
        }

示例2:

       利用计时器,随机数,每隔段时间就更新图片

        int i = 0;
        string[] path = Directory.GetFiles(@"C:\Users\Administrator\Desktop\图片");
        Random r = new Random();
        private void timer_click()
        {
            i++;
            if(i==path.length)
           {
                i=0;
           }
           picturebox1.Image = Image.FormFile(path(r.Next(0,path.Length)));
       }         

 

posted @ 2016-05-26 20:59  寒夜美美  阅读(666)  评论(0编辑  收藏  举报