看来问题很难一次说清,分开发。

bulls5988 2010-10-12 09:31:55
现在输出的第一条记录的图片。
我要做图片循环,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);
}
...全文
95 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kensouterry 2010-10-13
  • 打赏
  • 举报
回复
这样能否满足楼主的要求,参考一下!

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;
//图片显示完毕
}
}



}
}
邋遢的土豆 2010-10-12
  • 打赏
  • 举报
回复
先把所有图片读出来 放到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;
}
}
bulls5988 2010-10-12
  • 打赏
  • 举报
回复

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]; ;
}
}
bulls5988 2010-10-12
  • 打赏
  • 举报
回复
没明白,你是说先把所有记录读进一个imagelist??
wuyq11 2010-10-12
  • 打赏
  • 举报
回复
List<T> 保存image
random随机数
Random rand = new Random(Guid.NewGuid().GetHashCode());
rand.Next(1,lst.Count)
lst[i]

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧