现在输出的第一条记录的图片。
我要做图片循环,timer运行的时候,如果后面还有记录就依次输出下面记录的图片和文字(第一条,第二条...第N-1条)应该怎么做? private void timer1_Tick(object sender, EventArgs e)
        {
            string sql_str = "select * from cj_main";
            SqlConnection conn = new SqlConnection(conn_str);
            SqlCommand command = new SqlCommand(sql_str, conn);
            conn.Open();
            SqlDataReader rs = command.ExecuteReader();
            if (rs.Read())
            {
                cj_names = rs[1].ToString();
                cj_pic_path=rs[3].ToString();
                this.pictureBox1.Image=Image.FromFile(cj_pic_path);               
            }

解决方案 »

  1.   

    List<T> 保存image
    random随机数 
    Random rand = new Random(Guid.NewGuid().GetHashCode());
    rand.Next(1,lst.Count)
    lst[i]
      

  2.   

    没明白,你是说先把所有记录读进一个imagelist??
      

  3.   


    private void timer1_Tick(object sender, EventArgs e)
            {
                string sql_str = "select * from cj_main";
                SqlConnection conn = new SqlConnection(conn_str);
                SqlCommand command = new SqlCommand(sql_str, conn);
                conn.Open();
                SqlDataReader rs = command.ExecuteReader();
                if (rs.Read())
                {
                    cj_names = rs[1].ToString();
                    cj_pic_path = rs[3].ToString();
                    List<Image> lst = new List<Image>();
                    lst.Add(Image.FromFile(cj_pic_path));
                    if (i >= lst.Count)
                    {
                        i = 0;
                    }
                    else
                    {
                        this.pictureBox1.Image = lst[i];
                        pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
                        i = i + 1;
                        this.pictureBox1.Image = lst[i]; ;
                    }
                }
      

  4.   

    先把所有图片读出来 放到ImageList控件里 然后Timer中 改变pictureBox中的图片就可以 了没有看懂楼主的意思。。不知道这样是想要的结果不
                
             private void Form1_Load(object sender, EventArgs e)
            {
                string sql_str = "select * from cj_main";
                SqlConnection conn = new SqlConnection(conn_str);
                SqlCommand command = new SqlCommand(sql_str, conn);
                conn.Open();
                SqlDataReader rs = command.ExecuteReader();
                while (rs.Read())
                {
                    cj_names = rs[1].ToString();
                    cj_pic_path = rs[3].ToString();
                    //添加到ImageList里面
                    this.imageList1.Images.Add(cj_names, Image.FromFile(cj_pic_path));
                }
            }
            private int index=0;//用来刷
            /// <summary>
            /// Timer来回刷实现循环
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>        
            private void timer1_Tick(object sender, EventArgs e)
            {           this.pictureBox1.Image = this.imageList1.Images[index++];
               if (index>=this.imageList1.Images.Count)//如果大于图片个数~重新开始
               {
                   index == 0;
               }
            }
      

  5.   

    这样能否满足楼主的要求,参考一下!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 WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            //假设这是你从数据库提取出来的ds数据集
            int[] _array = new int[5] { 1, 2, 3, 66, 77 };
            //用来 记录图片的索引位置,类成员
            int _picIndex = -1;        public Form1()
            {
                InitializeComponent();
                
                //button1_Click(null, null);
                timer1.Enabled = true;
            }        private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("Hello,World");
            }
            /// <summary>
            /// Display each number sequence.
            /// 弹出的5个对话框就代表你显示的图片和文字
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void timer1_Tick(object sender, EventArgs e)
            {
                if (_picIndex < _array.Length-1)
                {
                    _picIndex++;
                    //假设MessageBox.Show就是你要显示的图片和文字
                    MessageBox.Show(_array[_picIndex].ToString());
                }
                else
                {
                    _picIndex = 0;
                    timer1.Enabled = false;
                    //图片显示完毕
                }
            }            }
    }