using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MsgDemo
{
public partial class Form1 : Form
{
private List<string> msg;
private int index = 0;
private Timer timer;
public Form1()
{
InitializeComponent();
//创建一个定时器
timer = new Timer();
timer.Interval = 3000; //每隔 3s 触发一次
timer.Tick += new EventHandler(timer_Tick);
}
private void Form1_Load(object sender, EventArgs e)
{
msg = ReadMsg();
//启动定时器
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
MessageBox.Show(msg[index++]);
if (index >= msg.Count) {
index = 0;
}
}
//从数据库读取数据到 msg 中
private List<string> ReadMsg()
{
List<string> msg = new List<string>();
msg.Add("asdf");
msg.Add("asdfdf");
msg.Add("dffdfafd");
msg.Add("gshdfh");
msg.Add("asdfa");
msg.Add("hdfhdfh");
return msg;
}
}
}