Ejemplo n.º 1
0
        /// <summary>
        /// Sends the selected character to the answer control (PEanswer) and sets the focus back on CharacterForm.
        /// </summary>
        /// <param name="sender">Button object that raised the event.</param>
        /// <param name="e">System.EventArgs that contains the event data.</param>
        /// <remarks>Documented by Dev03, 2007-07-20</remarks>
        private void SomeButtons_Click(object sender, System.EventArgs e)
        {
            // Add symbol to currently focused control
            string Symbol = (string)(sender as Button).Tag;

            if (CurrentControl != null)
            {
                if (CurrentControl is MLifter.Components.MLifterTextBox)
                {
                    (CurrentControl as MLifter.Components.MLifterTextBox).SendChar(Symbol[0]);
                }
                else if (CurrentControl is TextBox)
                {
                    TextBox textbox        = CurrentControl as TextBox;
                    int     selectionstart = textbox.SelectionStart;
                    string  newtext        = string.Empty;
                    newtext               += textbox.Text.Substring(0, textbox.SelectionStart);
                    newtext               += Symbol;
                    newtext               += textbox.Text.Substring(textbox.SelectionStart + textbox.SelectionLength, textbox.Text.Length - textbox.SelectionStart - textbox.SelectionLength);
                    textbox.Text           = newtext;
                    textbox.SelectionStart = selectionstart + Symbol.Length;
                }
                else if (CurrentControl is ListView && CurrentControl.Parent.Parent is CardEdit)
                {
                    (CurrentControl.Parent.Parent as CardEdit).SendListViewChar(Symbol, (ListView)CurrentControl);
                }

                this.TopMost = true;

                // Set focus back
                if (CurrentControl.Visible)
                {
                    CurrentControl.Focus();
                }
            }
        }
        private void BtnDienKhuyet_Click(object sender, EventArgs e)
        {
            txtCtrlNoiDungCauHoi.Focus();
            //Them vao cau tra loi
            if (txtCtrlNoiDungCauHoi.SelectionLength == 0)
            {
                UICommon.ShowMsgWarningString("Bạn chưa chọn nội dung cần điền khuyết");
                return;
            }
            var textStart = txtCtrlNoiDungCauHoi.SelectionStart;

            //Kiem tra vi tri dien khuyet
            if (_mathCollection != null)
            {
                for (int i = 0; i < _mathCollection.Count; i++)
                {
                    var viTriNext = _mathCollection[i].Index + _mathCollection[i].Length;
                    if (textStart >= _mathCollection[i].Index && textStart <= viTriNext)
                    {
                        UICommon.ShowMsgWarningString("Vị trí điền khuyết không hợp lệ!");
                        if (txtCtrlNoiDungCauHoi.SelectionLength == 0)
                        {
                            txtCtrlNoiDungCauHoi.Undo();
                        }
                        return;
                    }
                }
            }

            var tmp = txtCtrlNoiDungCauHoi.SelectedRtf;

            //Buoc 2: Add cau tra loi dau tien cho cau hoi hien tai => vi trí diền khuyết
            if (txtCtrlNoiDungCauHoi.SelectionLength != 0)
            {
                //Gan du lieu toan cuc và cboCauHoi
                CauHoiCurent = new EX_CauHoi {
                    IDEx = ListCauHoi.Count + 1, DoKho = IdMucDoNhanThuc
                };
                //Buoc 1
                ListCauHoi.Add(CauHoiCurent);
                CauHoiCurent.ListCauTraLoi.Add(new EX_CauTraLoi {
                    IdEx = 1, NoiDung = txtCtrlNoiDungCauHoi.SelectedRtf, IndexEx = textStart
                });

                var textStt = string.Format("({0})_____", ListCauHoi.Count);
PasteClipboard:
                {
                    try
                    {
                        Clipboard.SetText(textStt);
                    }
                    catch (Exception)
                    {
                        goto PasteClipboard;
                    }
                }
                txtCtrlNoiDungCauHoi.Paste();
            }
            else
            {
                UICommon.ShowMsgWarningString("Nội dung chọn không hợp lệ");
                if (txtCtrlNoiDungCauHoi.SelectionLength == 0)
                {
                    txtCtrlNoiDungCauHoi.Undo();
                }
                return;
            }

            //Buoc 3: do du lieu len cbo
            if (ListCauHoi.Count > 0)
            {
                SetDataToCboCauHoi();
            }
            //Buoc 4 => changCategoryID
            _isDienKhuyet        = true;
            cboCauHoi.CategoryID = ListCauHoi.Count;
            IdCauHoiCurent       = (int)cboCauHoi.CategoryID;

            //Ve lai cau hoi => phan ben trai
            ClearAllCauTraLoi();
            ClearAllCauTraLoiGayNhieu();
            ThemCauTraLoi();

            CurrentControl.Focus();
            CurrentControl.Rtf      = tmp;
            CurrentControl.ReadOnly = true;

            // Nhận dạng lại vị trí
            _mathCollection = _parsing.ParseDienKhuyet2(txtCtrlNoiDungCauHoi.Text);
        }