Example #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();
            }
        }
Example #2
0
        private void ScrollText()
        {
            //Tự động scroll văn bản trong RTB_String khi đánh đến dòng cuối đang được hiển thị
            if (PositionKey == location - 1 && location != RTB_String.Text.Length - 1)
            {
                //Xác định vị trí cần scroll
                RTB_String.SelectionStart = location;
                RTB_String.ScrollToCaret();

                //Tìm index ký tự cuối cùng được hiển thị để scroll lần sau
                location = RTB_String.GetCharIndexFromPosition(new Point(RTB_String.ClientSize.Width, RTB_String.ClientSize.Height));
            }
        }
Example #3
0
        public Frm_Typing()
        {
            InitializeComponent();

            //Căn lề cho văn bản trong RTB_String

            /*RTB_String.SelectAll();
             * RTB_String.SelectionAlignment = HorizontalAlignment.Center;
             * RTB_String.DeselectAll();*/

            //Tìm index ký tự cuối cùng được hiển thị để scroll
            location = RTB_String.GetCharIndexFromPosition(new Point(RTB_String.ClientSize.Width, RTB_String.ClientSize.Height));
        }
Example #4
0
        //public Frm_Typing(List<string> text, int t)
        //{
        //    //TODO: Thay đổi kích thước font chữ trong RTB_String theo từng loại

        //    InitializeComponent();
        //    time = t;
        //    timeLeft = t;
        //    exerciseText = text;
        //    if (time < 3600)
        //    {
        //        lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"mm\:ss");
        //    }
        //    else
        //    {
        //        lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"hh\:mm\:ss");
        //    }
        //    RTB_String.Lines = exerciseText.ToArray();

        //    //Tìm index ký tự cuối cùng được hiển thị để scroll
        //    location = RTB_String.GetCharIndexFromPosition(new Point(RTB_String.ClientSize.Width, RTB_String.ClientSize.Height));
        //}
        public Frm_Typing(DTO_Exercise ob)
        {
            InitializeComponent();
            objectmodel = ob;
            time        = objectmodel.Timeleft;
            Title       = objectmodel.Title;
            NameFile    = objectmodel.FileName;
            PositionKey = objectmodel.Position;
            //exerciseText = objectmodel.ExerciseText;
            //BUS.BUS_Typing.FindContent(ob, ref time, ref Title, ref NameFile,ref exerciseText);
            this.type = objectmodel.ExerciseType;

            //Thay đổi kích thước font chữ trong RTB_String theo từng loại
            switch (type)
            {
            case "Word":
                RTB_String.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F);
                break;

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

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

            //Xoá các ký tự trằng đầu và cuối đoạn văn, thêm ký hiệu "↵" vào cuối đoạn.
            foreach (string line in objectmodel.ExerciseText)
            {
                if (line.Trim() != "")
                {
                    exerciseText.Add(line.Trim() + "↵");
                }
            }

            timeLeft = time;
            if (time < 3600)
            {
                lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"mm\:ss");
            }
            else
            {
                lbTimer.Text = TimeSpan.FromSeconds(timeLeft).ToString(@"hh\:mm\:ss");
            }
            RTB_String.Lines = exerciseText.ToArray();

            //Đếm số câu trong bài, dùng cho ProgressBar
            for (int i = 0; i < RTB_String.Text.Length; i++)
            {
                if (RTB_String.Text[i] == '.' || RTB_String.Text[i] == '?' || RTB_String.Text[i] == '↵')
                {
                    numSentence++;
                }

                if (i > 0 && RTB_String.Text[i] == '↵' && (RTB_String.Text[i - 1] == '.' || RTB_String.Text[i - 1] == '?'))
                {
                    numSentence--;
                }

                if (i < PositionKey)
                {
                    curSentence = numSentence;
                }
            }

            if (ob.Star > 0) //Đã hoàn thành
            {
                finished    = true;
                curSentence = numSentence;
            }

            //Cập nhật ProgressBar
            progressBar1.Maximum = numSentence;
            lbStatus.Text        = "Progress: " + curSentence + "/" + numSentence + " sentence.";

            //Nếu form dùng hiển thị bài học thì ẩn nút save
            if (objectmodel.IsLesson == true)
            {
                btn_save.Hide();
            }

            //Tìm index ký tự cuối cùng được hiển thị để scroll
            location = RTB_String.GetCharIndexFromPosition(new Point(RTB_String.ClientSize.Width, RTB_String.ClientSize.Height));
            LoadKeyPressed();
            ScrollText();
        }
Example #5
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;
                    }
                }
            }
        }
Example #6
0
 void LoadKeyPressed()
 {
     RTB_String.Select(0, PositionKey);
     RTB_String.SelectionColor = Color.Green;
 }