Example #1
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 #2
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 #3
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();
        }