namespace WinFormsApp7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int wctr = 0;
int intervalCtr = 0;
string str1 = "向晚意不適,驅車登古原,夕陽無限好,只是近黃昏";
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Interval = 100;
label1.Text = str1.Substring(0, 1);
label2.Text = "";
Text = "打字練習";
label3.Text = "字數統計:" + wctr.ToString();
}
int tc = 0;
private void timer1_Tick(object sender, EventArgs e)
{
label1.Top += 10;
intervalCtr++;
if (label1.Top > label2.Top)
{
label2.Text += label1.Text;
tc++;
tc = tc % str1.Length;
label1.Text = str1[tc].ToString();
label1.Top = 27;
}
label4.Text = intervalCtr / 10 + " sec";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.Text == label1.Text)
{
wctr++;
label3.Text = "字數統計:" + wctr.ToString();
textBox1.Text = "";
tc++;
tc = tc % str1.Length;
label1.Text = str1[tc].ToString();
label1.Top = 27;
}
if (!string.IsNullOrEmpty(textBox1.Text))
{
if (label2.Text.Contains(textBox1.Text))
{
wctr++;
label3.Text = "字數統計:" + wctr.ToString();
label2.Text = label2.Text.Replace(textBox1.Text, "");
textBox1.Text = "";
}
}
}
}
}