C # back word applet

This lecture is about file and stream operations. Let's do a comprehensive but not too complicated program to "remember words".

Requirements are as follows:

(4 points) Ability to read the contents of the English level 4 word text file and put it into an array or list in memory (use StreamReader to read ReadLine () or ReadToEnd () directly, and then use String Split ('\ n' ) Split into multiple lines; then for each line Trim (). Split ('\ t') the 0th string [] is the English word, the 1st is the Chinese meaning, you can put it in two arrays or List).

(4 points) Use Da Shi ’s favorite Timer to display English words and Chinese meanings on the screen at regular intervals (two label controls can be used). (Note that there must be a subscript variable, which is added every time to achieve different words displayed each time). (Another reminder: Set the TopMost property of the form to True, the form will not be covered by other windows, and you can memorize the words anytime, anywhere!)

(2 points) You can add tricks, such as random, such as allowing users to adjust the speed of memorizing words, or you can make the interface cooler, the more advanced is to save the progress, and the more advanced is to use Ai Binhao Sri Lanka's forgetting curve (our job requirements should not be so high, no matter how high it is a commercial software requirements, huh).

operation result:

 

code show as below:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int t1 = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            #regionRead data from file      
            List < string > english = new List < string > ();
            List<string> chinese = new List<string>(); 
            StreamReader sw = new StreamReader("F:\\College_Grade4.txt", Encoding.Default); 
            string content = sw.ReadToEnd(); 
            string[] lines = content.Split('\n'); 
            for (int i = 0; i < lines.Length; i++)
            {
                string[] words = lines[i].Trim().Split('\t'); 
                if (words.Length < 2) 
                    continue;
                english.Add(words[0]); 
                chinese.Add(words[1]);
                 
            }
            
            if (t1 < lines.Length)
            {
                this.label1.Text = english[t1];
                this.label2.Text = chinese[t1];

            }
            t1++;
            this.label6.Text = t1.ToString();
            #endregion
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i = Convert.ToInt32(this.textBox1.Text);
            this.timer1.Interval = i;

        }
    }
}

Reference materials:

https://docs.microsoft.com/zh-cn/dotnet/api/system.threading.timer?redirectedfrom=MSDN&view=netframework-4.8

https://blog.csdn.net/u011367578/article/details/82951985?utm_source=blogxgwz0

Guess you like

Origin www.cnblogs.com/Amanda-Y/p/12671916.html