110,535
社区成员
发帖
与我相关
我的任务
分享
string[] lines;//所有文字,每行都有回车
int nextLine; //下一行
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Text =Resources.String1;
lines=richTextBox1.Lines;
richTextBox1.Text = "";
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
void timer1_Tick(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder(richTextBox1.Text);
if (richTextBox1.Text != "")
{
sb.Append("\r\n");
}
sb.Append(lines[nextLine]); //添加下一行文字
richTextBox1.Text = sb.ToString();
richTextBox1.Select();
richTextBox1.SelectionStart = richTextBox1.Text.Length;
nextLine++;
if (nextLine >= lines.Length)
{
timer1.Enabled = false;
}
}
public partial class Form1 : Form
{
Timer timer = new Timer();
string[] lines = { "hellow world", "nihao", "line3", "line4", "line5", "end" };
int currentLine = 0;
public Form1()
{
InitializeComponent();
timer.Interval = 300;
timer.Tick += delegate { currentLine++; this.Invalidate(); };
timer.Start();
}
protected override void OnPaint(PaintEventArgs e)
{
for (int i = 0; i < currentLine % lines.Length; i++)
{
e.Graphics.DrawString(lines[i], this.Font, Brushes.Black, 10, 20 * i);
}
}
}