Exemplo n.º 1
0
        private void Frm_Typing_Load(object sender, EventArgs e)
        {
            // Start the BackgroundWorker.
            backgroundWorker1.RunWorkerAsync();

            //finished = false;
            aTimer.Tick    += ATimer_Tick;
            aTimer.Interval = 3000;
            // danh cho check van ban
            //richTextBox1.Select(0,1);
            //richTextBox1.SelectionColor = Color.Green;
            //richTextBox1.Select(1, 3);
            //richTextBox1.SelectionColor = Color.Red;
            //RandomString();

            if (finished == true && PositionKey != 0)
            {
                PositionKey--;
            }

            int iAscii = RTB_String.Text[PositionKey];

            RTB_String.Select(0, PositionKey);
            RTB_String.SelectionColor = Color.Green;
            RTB_String.SelectionFont  = new System.Drawing.Font("Microsoft Sans Serif", 14.5F, System.Drawing.FontStyle.Underline);

            BUS_Typing.StopFocus(this);
            Control ctn = FindControlByTag(pn_Keys, iAscii); //.Controls[name];

            if (ctn != null)
            {
                HighLight((Button)ctn);
                HighLightShift(RTB_String.Text[PositionKey]);
            }
            if (PositionKey < RTB_String.Text.Length)
            {
                SetFingerVisible(RTB_String.Text[PositionKey].ToString().ToLower());
            }
            this.KeyPreview = true;

            if (finished == true)
            {
                Frm_Rating rating;

                if (canRemake == true)
                {
                    rating = new Frm_Rating(objectmodel.Star, objectmodel, timeLeft, PositionKey);
                }
                else
                {
                    rating = new Frm_Rating(objectmodel.Star);
                }

                this.Show();
                rating.ShowDialog(this);
                this.Close();
            }
        }
Exemplo n.º 2
0
        private void Frm_Typing_KeyPress(object sender, KeyPressEventArgs e)
        {
            ScrollText();

            if (timer1.Enabled == false)
            {
                timer1.Start();
            }

            if (PositionKey >= RTB_String.Text.Length)
            {
                return;
            }
            char keyText = RTB_String.Text[PositionKey];// Chuoi[z];
            int  compare = keyText;

            if (keyText == '↵')
            {
                compare = 8629;
            }

            //string stringlabel = key.ToString().ToLower();
            if (e.KeyChar > 31 && e.KeyChar < 127 || e.KeyChar == 13)
            {
                //char ch = (char)e.KeyChar;
                //string str = ch.ToString();
                int iAscii = e.KeyChar;

                //8629 là mà Ascii của "↵"
                if (e.KeyChar == 13)
                {
                    iAscii = 8629;
                }

                Control ctn = FindControlByTag(pn_Keys, iAscii); //.Controls[name];
                if (ctn != null)
                {
                    //((Button)ctn).Focus();
                    //char cKeylabel = stringlabel.ToCharArray()[0];
                    //char cKeylabel = stringlabel.ToCharArray()[0];
                    //int iKeylabel = cKeylabel;

                    //if (SearchStringInTagControl(ctn, keyText) == true) //if (SearchStringInTagControl(ctn, iKeylabel) == true)
                    if (iAscii == compare)
                    {
                        if (e.KeyChar.ToString() == @"\")
                        {
                            SoundPlayer sn = new SoundPlayer(@"sound\secphai.wav");
                            sn.Play();
                        }
                        else if (e.KeyChar.ToString() == @"/")
                        {
                            SoundPlayer sn = new SoundPlayer(@"sound\sectrai.wav");
                            sn.Play();
                        }
                        else if (e.KeyChar.ToString() == ".")
                        {
                            SoundPlayer sn = new SoundPlayer(@"sound\cham.wav");
                            sn.Play();
                        }
                        else if (e.KeyChar.ToString() == " ")
                        {
                            SoundPlayer sn = new SoundPlayer(@"sound\space.wav");
                            sn.Play();
                        }
                        else if (e.KeyChar.ToString() == "[" || e.KeyChar.ToString() == "]")
                        {
                            SoundPlayer sn = new SoundPlayer(@"sound\[].wav");
                            sn.Play();
                        }
                        else if (Regex.Match(e.KeyChar.ToString(), "[A-Za-z0-9]").Length != 0)
                        {
                            SoundPlayer sn = new SoundPlayer(@"sound\" + e.KeyChar.ToString().ToLower() + ".wav");
                            sn.Play();
                        }
                        else
                        {
                            SoundPlayer sn = new SoundPlayer(@"sound\shift-key.wav");
                            sn.Play();
                        }

                        RTB_String.Select(PositionKey, 1);
                        RTB_String.SelectionColor = Color.Green;

                        if ((keyText == '.' || keyText == '?') && RTB_String.Text[PositionKey + 1] != '↵')
                        {
                            ChangeInfo();
                        }

                        if (keyText == '↵')
                        {
                            ChangeInfo();
                        }

                        switch (type)
                        {
                        case "Word":
                            RTB_String.SelectionFont = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Underline);
                            break;

                        case "Sentence":
                            RTB_String.SelectionFont = new System.Drawing.Font("Microsoft Sans Serif", 27.5F, System.Drawing.FontStyle.Underline);
                            break;

                        case "Paragraph":
                            RTB_String.SelectionFont = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Underline);
                            break;
                        }

                        PositionKey++;
                        if (PositionKey < RTB_String.Text.Length)
                        {
                            iAscii = RTB_String.Text[PositionKey];
                            ctn    = FindControlByTag(pn_Keys, iAscii);//FindControl(pn_Keys, "btn" + stringlabel);
                            //if (ctn != null)
                            //{
                            //    HighLight((Button)ctn);
                            //    SetFingerVisible(RTB_String.Text[z].ToString().ToLower());
                            //}
                            while (ctn == null && PositionKey < RTB_String.Text.Length)
                            {
                                PositionKey++;
                                iAscii = RTB_String.Text[PositionKey];
                                ctn    = FindControlByTag(pn_Keys, iAscii);
                            }
                            ;
                            HighLight((Button)ctn);
                            HighLightShift(RTB_String.Text[PositionKey]);
                            Normal(btn_oldHighLight1);
                            SetFingerVisible(RTB_String.Text[PositionKey].ToString().ToLower());
                        }
                    }
                    else
                    {
                        SoundPlayer sn1 = new SoundPlayer(@"sound\wrong.wav");
                        sn1.Play();
                        RTB_String.Select(PositionKey, 1);
                        RTB_String.SelectionColor = Color.PaleVioletRed;

                        switch (type)
                        {
                        case "Word":
                            RTB_String.SelectionFont = new System.Drawing.Font("Microsoft Sans Serif", 36.5F, System.Drawing.FontStyle.Underline);
                            break;

                        case "Sentence":
                            RTB_String.SelectionFont = new System.Drawing.Font("Microsoft Sans Serif", 28.5F, System.Drawing.FontStyle.Underline);
                            break;

                        case "Paragraph":
                            RTB_String.SelectionFont = new System.Drawing.Font("Microsoft Sans Serif", 14.5F, System.Drawing.FontStyle.Underline);
                            break;
                        }

                        Button_FalseShift((char)e.KeyChar, RTB_String.Text[PositionKey]);
                        Button_False((Button)ctn);
                    }

                    if (PositionKey == RTB_String.Text.Length)
                    {
                        finished = true;
                    }
                }
            }
        }
Exemplo n.º 3
0
 void LoadKeyPressed()
 {
     RTB_String.Select(0, PositionKey);
     RTB_String.SelectionColor = Color.Green;
 }