コード例 #1
0
 private void BtnThemGayNhieu_Click(object sender, EventArgs e)
 {
     //đẩy vào cau hoi hien tai 1 cau tra loi tuong ung
     if (CauHoiCurent != null)
     {
         var cauTraLoi = new EX_CauTraLoi();
         cauTraLoi.IdEx = CauHoiCurent.ListCauTraLoi.Count + 1;
         CauHoiCurent.ListCauTraLoi.Add(cauTraLoi);
         ThemCauTraLoiGayNhieu(cauTraLoi);
     }
 }
コード例 #2
0
        private void ThemCauTraLoiGayNhieu(EX_CauTraLoi cauTraLoi = null)
        {
            //add more 2 new rows
            tblPanelMain2.RowCount += 2;
            int rowIndex = tblPanelMain2.RowStyles.Add(new RowStyle(SizeType.Absolute, 63F));

            tblPanelMain2.RowStyles.Add(new RowStyle(SizeType.Absolute, 0));

            // Đáp án gây nhiễu sẽ tính từ a,b,c,d
            Label lblCauHoi = new Label()
            {
                Width = 40, Dock = DockStyle.Right, Name = _nameLabelDapAn, Tag = 0, Font = new Font(Font.FontFamily, 11, FontStyle.Bold), TextAlign = ContentAlignment.MiddleCenter
            };                                                                                                                                                                                                       //Tag = 1 = true, Tag = 0 = false

            lblCauHoi.Text = Convert.ToChar(65 + _lstTablePanelGayNhieu.Count).ToString();

            // Xóa câu trả lời
            var btnXoa = new DevExpress.XtraEditors.SimpleButton();

            btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete;
            btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter;
            btnXoa.Dock    = System.Windows.Forms.DockStyle.Left;
            btnXoa.Margin  = new System.Windows.Forms.Padding(2);
            btnXoa.Name    = _nameButtonXoa;
            btnXoa.Text    = "";
            btnXoa.Width   = 40;
            btnXoa.ToolTip = "Xóa câu trả lời gây nhiễu";
            btnXoa.Click  += new EventHandler(XoaCauTraLoiGayNhieu);

            //EditorControl
            EditorControl txtCtrl = new EditorControl()
            {
                Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BorderStyle = BorderStyle.FixedSingle, Margin = new Padding(2)
            };

            txtCtrl.GotFocus += TxtCtrlNoiDungCauHoi_GotFocus;

            // Table panel
            TableLayoutPanel tblPanelDapAnGayNhieu = new TableLayoutPanel();

            tblPanelDapAnGayNhieu.Name        = _nameTablePanelDapAn + rowIndex;
            tblPanelDapAnGayNhieu.ColumnCount = 3;
            tblPanelDapAnGayNhieu.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F));
            tblPanelDapAnGayNhieu.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
            tblPanelDapAnGayNhieu.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F));
            tblPanelDapAnGayNhieu.RowCount = 1;
            tblPanelDapAnGayNhieu.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
            tblPanelDapAnGayNhieu.Dock = DockStyle.Top;

            tblPanelDapAnGayNhieu.Controls.Add(lblCauHoi, 0, 0);
            tblPanelDapAnGayNhieu.Controls.Add(txtCtrl, 1, 0);
            tblPanelDapAnGayNhieu.Controls.Add(btnXoa, 2, 0);

            tblPanelMain2.Controls.Add(tblPanelDapAnGayNhieu, 0, rowIndex);
            //add panel to list
            _lstTablePanelGayNhieu.Add(tblPanelDapAnGayNhieu);

            if (cauTraLoi != null)
            {
                // Load noi dung dap an
                if (!string.IsNullOrEmpty(cauTraLoi.NoiDung))
                {
                    txtCtrl.Rtf = cauTraLoi.NoiDung;
                }

                // Gán id câu trả lời
                btnXoa.Tag = cauTraLoi.Id;
                tblPanelDapAnGayNhieu.Tag = cauTraLoi.IdEx;
            }
            CurrentControl = txtCtrl;
        }
コード例 #3
0
        private void ThemCauTraLoi(EX_CauTraLoi cauTraLoi = null)
        {
            //add more 2 new rows
            tblPanelMain.RowCount += 2;
            int rowIndex = tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 63F));

            tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 0));

            // Đáp án đúng
            Label lblCauHoi = new Label()
            {
                Width = 40, Dock = DockStyle.Right, Name = _nameLabelDapAn, Tag = 0, Font = new Font(Font.FontFamily, 11, FontStyle.Bold), TextAlign = ContentAlignment.MiddleCenter
            };                                                                                                                                                                                                       //Tag = 1 = true, Tag = 0 = false

            lblCauHoi.Text = (_isDienKhuyet ? ListCauHoi.Count : IdCauHoiCurent).ToString();

            // Xóa câu trả lời
            var btnXoa = new DevExpress.XtraEditors.SimpleButton();

            btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete;
            btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter;
            btnXoa.Dock    = System.Windows.Forms.DockStyle.Left;
            btnXoa.Margin  = new System.Windows.Forms.Padding(2);
            btnXoa.Name    = _nameButtonXoa;
            btnXoa.Text    = "";
            btnXoa.Width   = 40;
            btnXoa.ToolTip = "Xóa câu trả lời";
            btnXoa.Click  += new EventHandler(XoaCauTraLoi);

            //EditorControl
            EditorControl txtCtrl = new EditorControl()
            {
                Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BackColor = Color.White, BorderStyle = BorderStyle.FixedSingle, ReadOnly = true, Margin = new Padding(2)
            };

            // Table panel
            TableLayoutPanel tblPanelDapAn = new TableLayoutPanel();

            tblPanelDapAn.Name        = _nameTablePanelDapAn + rowIndex;
            tblPanelDapAn.ColumnCount = 3;
            tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F));
            tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
            tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F));
            tblPanelDapAn.RowCount = 1;
            tblPanelDapAn.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
            tblPanelDapAn.Dock = DockStyle.Top;

            tblPanelDapAn.Controls.Add(lblCauHoi, 0, 0);
            tblPanelDapAn.Controls.Add(txtCtrl, 1, 0);
            tblPanelDapAn.Controls.Add(btnXoa, 2, 0);

            tblPanelMain.Controls.Add(tblPanelDapAn, 0, rowIndex);
            //add panel to list
            _lstTablePanelCauHoi.Add(tblPanelDapAn);

            if (cauTraLoi != null)
            {
                // Load noi dung dap an
                txtCtrl.Rtf = cauTraLoi.NoiDung;
                // Gán id câu trả lời
                btnXoa.Tag = cauTraLoi.Id;
            }
            CurrentControl          = txtCtrl;
            CurrentControl.ReadOnly = true;
        }