C#中timer 控件的一段程序
来源:百度知道 编辑:UC知道 时间:2024/06/07 00:04:10
我是这样 做出来的。控件:TextBox,Button,Timer。
Timer的Interval值设为1000.在项目的Debug目录下放置test.txt文件,内容为1234567890amxjdhflsjdaflkdfisdfwergghh.......;执行后一秒一变
..
using System.IO;
..
public int i = 0;
public string st = "";
..
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
string str = File.ReadAllText("../Debug/test.txt", Encoding.Default);
if (i == 1)
{
this.textBox1.Text = str.Substring(0, i);
st = st + this.textBox1.Text;
}
else
{
this.textBox1.Text=str.Substring(st.Length,1);
st = st + this.textBox1.Text;
}
i++;
}
用到的控件:button,lable,timer;
int num=0; //定义一个全部变量
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Enlable=true;
}
pri