现在输出的第一条记录的图片。
我要做图片循环,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);
}
我要做图片循环,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);
}
解决方案 »
- 报表的数据源的SQL语句不能指定多个数据表,为什么呀
- 探测端口!
- 请教一个关于datatable的问题
- 关闭浏览器时执行的程序怎么写?
- 点击datagrid 的自动排序后 找不到选定的行了?
- HttpWebRequest上传文件,文件内的中文在服务器上变成了乱码,怎么解决
- 紧急求助,关于用C#引用Por E
- installutil.exe的问题,哪个好心人举个例子?
- windows DataGridView 刷新问题
- ASP.NET中调用Crystal report(C#),如何实现printtoprinter?急,代码详见内容
- .net2003程序转换为.net2005后无法输入汉字
- 将access表中的ole字段里的图片取出来
random随机数
Random rand = new Random(Guid.NewGuid().GetHashCode());
rand.Next(1,lst.Count)
lst[i]
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]; ;
}
}
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;
}
}
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;
//图片显示完毕
}
} }
}