111,129
社区成员
发帖
与我相关
我的任务
分享
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);
}
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;
//图片显示完毕
}
}
}
}
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;
}
}
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]; ;
}
}