本帖最后由 w5057723 于 2010-12-26 16:32:52 编辑

解决方案 »

  1.   

    取出字符串相同部分
    var c=str[0].ToCharArray().Intersect(TextBox1.Text.ToCharArray()).ToArray(); 
      

  2.   

    char[] chars = juzi[0].ToCharArray();
    然后取 chars[0] 里的字符================================public partial class Form1 : Form
        {
            char[] chats = null;
            public Form1()
            {
                InitializeComponent();
                this.richTextBox1.Text = "Last week I went to the theatre. I had avery good seat. I looked at the man and the woman angrily.";
                chats = richTextBox1.Text.ToCharArray();
                this.richTextBox1.SelectionStart = 0;
                this.richTextBox1.SelectionLength = 1;
                this.richTextBox1.SelectionColor = Color.Blue;
            }        private void Form1_Load(object sender, EventArgs e)
            {
            }
            
            
            // 键盘按下并释放后的事件调用方法
            private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                //       [选定字符起始位置]
                if (chats[richTextBox1.SelectionStart] == e.KeyChar)
                {
                    //  正确
                }
                else
                {
                    // 错误
                    richTextBox1.SelectionColor = Color.Red;
                }
                richTextBox1.SelectionStart++;
                richTextBox1.SelectionColor = Color.Blue;
                
            }
        }
      

  3.   

    简单注释了一下。你看下public partial class Form1 : Form
        {
            // 字符串数组
            string[] juzi = { "Last week I went to the theatre. I had avery good seat.", "I looked at the man and the woman angrily.",
      "They were talking loudly. I got very angry.", "It was Sunday. I never get up early on Sundays.",
      "Last Sunday I got up very late.","I am only interested in sitting in a boat and doing nothing at all !",
      "Aeroplanes are slowly driving me mad.", "I am one of the few people left.", "We have an old musical instrument.",
      "It is being repaired by a friend of my father's.","Ten minutes later we walked out of the shop together."
      };
            char[] chats = null;// 声明一个字符数组        public Form1()
            {InitializeComponent();// 忽略
                
                // 在这下面,主窗体的构造函数中初始化要用的变量            // 设置文本框中的文本   juzi 是个字符串数组 ,这里只取第一个下标的字符串
                // 如果想用 juzi 字符串数组里的其他文本,改[]下标
                this.richTextBox1.Text = juzi[0];            // richTextBox1.Text 是文本框中的字符串,调用 ToCharArray() 方法会将这串字符转换成一个 字符数组,
                // 返回的字符数组赋给前面声明的 chats 字符数组
                chats = richTextBox1.Text.ToCharArray();
                this.richTextBox1.SelectionStart = 0;// 这里设置文本框光标的选定起始点
                this.richTextBox1.SelectionLength = 1;// 这里设置文本框光标要选定几个字符
                this.richTextBox1.SelectionColor = Color.Blue;// 这里设置文本框光标选定字符的颜色为蓝色
            }        
            private void Form1_Load(object sender, EventArgs e)
            {
                // 文本框的事件委托(在文本有输入焦点时,按下键时发生) ,事件发生时 让它调用下面的richTextBox1_KeyPress()方法
                this.richTextBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.richTextBox1_KeyPress);
            }        // 键盘按下并释放后的事件调用方法
            // 当在键盘上按下,并弹起后会执行这个方法
            private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                // [选定字符起始位置]。
                // chats 字符数组[]中写个下标,
                // richTextBox1.SelectionStart也就是当前文本框的选定的第几个字符
                // 用参数 e.KeyChar 属性得到键盘按下的哪个字符
                // 并与 chats[] 里的字符,进行比较
                if (chats[richTextBox1.SelectionStart] == e.KeyChar)
                {
                    // 如果上面 if 判断为 true ,
                    // 表示正确,这里面写其他,正确时要做的事,如:正确数加1 
                }
                else
                {   // 如果上面 if 判断为 false ,
                    // 错误     设置文本框光标选定字符的颜色为红色
                    richTextBox1.SelectionColor = Color.Red;                // 错误数加1
                }
                richTextBox1.SelectionStart++;// 让光标加一,
                richTextBox1.SelectionColor = Color.Blue;// 设置文本框光标选定字符的颜色为蓝色        }
      

  4.   

    记得将文本框改成只读richTextBox1.ReadOnly = true;
      

  5.   

    取出字符串相同部分
    var c=str[0].ToCharArray().Intersect(TextBox1.Text.ToCharArray()).ToArray();